<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
	xmlns:bml="http://bookml.googlecode.com" xmlns:test="http://xsltut.googlecode.com"
	xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:exsl="http://exslt.org/common">
	<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
	<xsl:key name="primary-index" match="bml:indexterm" use="bml:primary"/>
	<xsl:key name="secondary-index" match="bml:indexterm"
		use="concat( bml:primary, ':', bml:secondary )"/>
	<xsl:key name="tertiary-index" match="bml:indexterm"
		use="concat( bml:primary, ':', bml:secondary, ':', bml:tertiary )"/>
	<xsl:param name="config"/>
	<xsl:param name="curdir"/>
	<xsl:variable name="cfg" select="document( translate( $config, '\', '/' ) )"/>
	<xsl:variable name="directory" select="($cfg//directory)[last()]"/>
	<xsl:variable name="page" select="($cfg//page)[last()]"/>
	<xsl:variable name="body-region" select="($cfg//region[ @name = 'body'])[last()]"/>
	<xsl:variable name="before-region" select="($cfg//region[ @name = 'before'])[last()]"/>
	<xsl:variable name="after-region" select="($cfg//region[ @name = 'after'])[last()]"/>
	<xsl:variable name="double-side" select="$page/@double-side"/>
	<xsl:variable name="page-height" select="$page/@height"/>
	<xsl:variable name="page-width" select="$page/@width"/>
	<xsl:variable name="margin-top" select="$page/@margin-top"/>
	<xsl:variable name="margin-bottom" select="$page/@margin-bottom"/>
	<xsl:variable name="margin-left" select="$page/@margin-left"/>
	<xsl:variable name="margin-right" select="$page/@margin-right"/>
	<xsl:variable name="even-margin-left" select="$page/@even-margin-left"/>
	<xsl:variable name="even-margin-right" select="$page/@even-margin-right"/>
	<xsl:variable name="odd-margin-left" select="$page/@odd-margin-left"/>
	<xsl:variable name="odd-margin-right" select="$page/@odd-margin-right"/>
	<xsl:variable name="author-surname-first" select="($cfg//author)[last()]/@surname-first"/>
	<xsl:variable name="copyright-text" select="($cfg//text[@name='copyright'])[last()]"/>
	<xsl:variable name="pubdate-text" select="($cfg//text[@name='pubdate'])[last()]"/>
	<xsl:variable name="chapter-text" select="($cfg//text[@name='chapter'])[last()]"/>
	<xsl:variable name="toc-text" select="($cfg//text[@name='toc'])[last()]"/>
	<xsl:variable name="revhistory-text" select="($cfg//text[@name='revhistory'])[last()]"/>
	<xsl:variable name="revision-text" select="($cfg//text[@name='revision'])[last()]"/>
	<xsl:variable name="foreword-text" select="($cfg//text[@name='foreword'])[last()]"/>
	<xsl:variable name="preface-text" select="($cfg//text[@name='preface'])[last()]"/>
	<xsl:variable name="appendix-text" select="($cfg//text[@name='appendix'])[last()]"/>
	<xsl:variable name="glossary-text" select="($cfg//text[@name='glossary'])[last()]"/>
	<xsl:variable name="index-text" select="($cfg//text[@name='index'])[last()]"/>
	<xsl:variable name="table-text" select="($cfg//text[@name='table'])[last()]"/>
	<xsl:variable name="image-text" select="($cfg//text[@name='image'])[last()]"/>
	<xsl:variable name="seeindex-text" select="($cfg//text[@name='seeindex'])[last()]"/>
	<xsl:variable name="seealsoindex-text" select="($cfg//text[@name='seealsoindex'])[last()]"/>
	<xsl:variable name="root-style" select="($cfg//style[ @name = 'root' ] )[last()]"/>
	<xsl:variable name="book-title-style" select="($cfg//style[ @name = 'book-title' ] )[last()]"/>
	<xsl:variable name="book-subtitle-style"
		select="($cfg//style[ @name = 'book-subtitle' ] )[last()]"/>
	<xsl:variable name="book-title-after-style"
		select="($cfg//style[ @name = 'book-title-after' ] )[last()]"/>
	<xsl:variable name="article-title-style"
		select="($cfg//style[ @name = 'article-title' ] )[last()]"/>
	<xsl:variable name="article-subtitle-style"
		select="($cfg//style[ @name = 'article-subtitle' ] )[last()]"/>
	<xsl:variable name="article-title-after-style"
		select="($cfg//style[ @name = 'article-title-after' ] )[last()]"/>
	<xsl:variable name="author-style" select="($cfg//style[ @name = 'author' ] )[last()]"/>
	<xsl:variable name="book-author-after-style"
		select="($cfg//style[ @name = 'book-author-after' ] )[last()]"/>
	<xsl:variable name="article-sect1-before-style"
		select="($cfg//style[ @name = 'article-section1-before' ] )[last()]"/>
	<xsl:variable name="book-info-style" select="($cfg//style[ @name = 'book-info' ] )[last()]"/>
	<xsl:variable name="article-info-style"
		select="($cfg//style[ @name = 'article-info' ] )[last()]"/>
	<xsl:variable name="book-chapter-title-style"
		select="$cfg//style[ @name = 'book-chapter-title' ][last()]"/>
	<xsl:variable name="section-title-style"
		select="($cfg//style[ @name = 'section-title' ] )[last()]"/>
	<xsl:variable name="footnote-style" select="($cfg//style[ @name = 'footnote' ] )[last()]"/>
	<xsl:variable name="emphasis-style" select="($cfg//style[ @name = 'emphasis' ] )[last()]"/>
	<xsl:variable name="revhistory-style" select="($cfg//style[ @name = 'revhistory' ] )[last()]"/>
	<xsl:variable name="revision-style" select="($cfg//style[ @name = 'revision' ] )[last()]"/>
	<xsl:variable name="revision-number-style"
		select="($cfg//style[ @name = 'revision-number' ] )[last()]"/>
	<xsl:variable name="list-style" select="($cfg//style[ @name = 'list' ] )[last()]"/>
	<xsl:variable name="caption-style" select="($cfg//style[ @name = 'caption' ] )[last()]"/>
	<xsl:variable name="table-style" select="($cfg//style[ @name = 'table' ] )[last()]"/>
	<xsl:variable name="table-cell-style" select="($cfg//style[ @name = 'table-cell' ] )[last()]"/>
	<xsl:variable name="table-header-style"
		select="($cfg//style[ @name = 'table-header' ] )[last()]"/>
	<xsl:variable name="table-footer-style"
		select="($cfg//style[ @name = 'table-footer' ] )[last()]"/>
	<xsl:variable name="book-toc-chapter-style"
		select="($cfg//style[ @name = 'book-toc-chapter' ] )[last()]"/>
	<xsl:variable name="book-toc-section1-style"
		select="($cfg//style[ @name = 'book-toc-section1' ] )[last()]"/>
	<xsl:variable name="book-toc-section2-style"
		select="($cfg//style[ @name = 'book-toc-section2' ] )[last()]"/>
	<xsl:variable name="article-toc-chapter-style"
		select="($cfg//style[ @name = 'article-toc-chapter' ] )[last()]"/>
	<xsl:variable name="article-toc-section1-style"
		select="($cfg//style[ @name = 'article-toc-section1' ] )[last()]"/>
	<xsl:variable name="article-toc-section2-style"
		select="($cfg//style[ @name = 'article-toc-section2' ] )[last()]"/>
	<xsl:variable name="dedication-style" select="($cfg//style[ @name = 'dedication' ] )[last()]"/>
	<xsl:variable name="para-style" select="($cfg//style[ @name = 'para' ] )[last()]"/>
	<xsl:variable name="code-style" select="($cfg//style[ @name = 'code' ] )[last()]"/>
	<xsl:variable name="program-style" select="($cfg//style[ @name = 'program' ] )[last()]"/>
	<xsl:variable name="admonition-style" select="($cfg//style[ @name = 'admonition' ] )[last()]"/>
	<xsl:variable name="admonition-title-style"
		select="($cfg//style[ @name = 'admonition-title' ] )[last()]"/>
	<xsl:variable name="admonition-body-style"
		select="($cfg//style[ @name = 'admonition-body' ] )[last()]"/>
	<xsl:variable name="important-style" select="($cfg//style[ @name = 'important' ] )[last()]"/>
	<xsl:variable name="warning-style" select="($cfg//style[ @name = 'warning' ] )[last()]"/>
	<xsl:variable name="note-style" select="($cfg//style[ @name = 'note' ] )[last()]"/>
	<xsl:variable name="draft-style" select="($cfg//style[ @name = 'draft' ] )[last()]"/>
	<xsl:variable name="callouts-style" select="($cfg//style[ @name = 'callouts' ] )[last()]"/>
	<xsl:variable name="callout-style" select="($cfg//style[ @name = 'callout' ] )[last()]"/>
	<xsl:variable name="glossary-term-style"
		select="($cfg//style[ @name = 'glossary-term' ] )[last()]"/>
	<xsl:variable name="glossary-def-style"
		select="($cfg//style[ @name = 'glossary-def' ] )[last()]"/>
	<xsl:variable name="quote-style" select="($cfg//style[ @name = 'quote' ] )[last()]"/>
	<xsl:variable name="blockquote-style" select="($cfg//style[ @name = 'blockquote' ] )[last()]"/>
	<xsl:variable name="cr" select="'&#10;'"/>
	<xsl:variable name="toclevel" select="/*/@toclevel"/>
	<xsl:variable name="draft" select="/*/@draft"/>
	<xsl:variable name="revision-ids">
		<xsl:for-each select="//bml:revision">
			<xsl:sort select="@data" order="descending"/>
			<xsl:value-of select="generate-id(.)"/>,
		</xsl:for-each>
	</xsl:variable>
	<xsl:variable name="last-revision-id">
		<xsl:value-of select="substring-before($revision-ids, ',')"/>
	</xsl:variable>
	<xsl:template match="/">
		<xsl:if test="not( $config )">
			<xsl:message terminate="yes">BookML Error : 'config' parameter not
			provided.</xsl:message>
		</xsl:if>
		<xsl:apply-templates/>
	</xsl:template>

	<xsl:template match="bml:book">
		<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
			<xsl:call-template name="put-style-block-attr">
				<xsl:with-param name="style" select="$root-style"/>
			</xsl:call-template>
			<xsl:call-template name="put-book-layout-master-set"/>
			<xsl:call-template name="put-book-front-matter-sequence"/>
			<xsl:apply-templates
				select="bml:foreword | bml:preface | bml:chapter | bml:appendix | bml:glossary | bml:index"
			/>
		</fo:root>
	</xsl:template>

	<xsl:template name="put-draft-image">
		<xsl:if test="$draft = 'true'">
			<xsl:variable name="url"
				select="concat( 'url(', $directory/@default-image, '/', $draft-style/@image, ')' )"/>
			<xsl:attribute name="background-image">
				<xsl:value-of select="$url"/>
			</xsl:attribute>
			<xsl:attribute name="background-attachment">fixed</xsl:attribute>
			<xsl:attribute name="background-repeat">no-repeat</xsl:attribute>
			<xsl:attribute name="background-position-horizontal">center</xsl:attribute>
			<xsl:attribute name="background-position-vertical">center</xsl:attribute>
		</xsl:if>
	</xsl:template>

	<xsl:template match="bml:article">
		<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
			<xsl:call-template name="put-style-block-attr">
				<xsl:with-param name="style" select="$root-style"/>
			</xsl:call-template>
			<xsl:call-template name="put-article-layout-master-set"/>
			<xsl:call-template name="put-article-sequence"/>
			<!--<xsl:apply-templates select="bml:appendix | bml:glossary | bml:index"/>-->
		</fo:root>
	</xsl:template>

	<xsl:template name="put-book-front-matter-sequence">
		<fo:page-sequence master-reference="fm-title" break-after="page" initial-page-number="1"
			force-page-count="no-force">
			<fo:static-content flow-name="title-after">
				<fo:block>
					<xsl:for-each select="bml:info">
						<fo:block>
							<xsl:call-template name="put-style-block-attr">
								<xsl:with-param name="style" select="$book-info-style"/>
							</xsl:call-template>
							<xsl:for-each select="bml:pubdate">
								<xsl:value-of select="$pubdate-text"/>
								<xsl:text> </xsl:text>
								<xsl:value-of select="."/>
							</xsl:for-each>
						</fo:block>
						<fo:block>
							<xsl:call-template name="put-style-block-attr">
								<xsl:with-param name="style" select="$book-info-style"/>
							</xsl:call-template>
							<xsl:for-each select="bml:copyright">
								<xsl:value-of select="$copyright-text"/>
								<xsl:text> </xsl:text>
								<xsl:for-each select="bml:year">
									<xsl:value-of select="."/>
									<xsl:if test="not( position() = last() )">, </xsl:if>
								</xsl:for-each>
								<xsl:text> </xsl:text>
								<xsl:value-of select="bml:holder"/>
							</xsl:for-each>
						</fo:block>
					</xsl:for-each>
				</fo:block>
			</fo:static-content>
			<fo:flow flow-name="xsl-region-body">
				<xsl:apply-templates select="bml:info"/>
			</fo:flow>
		</fo:page-sequence>

		<xsl:if test="bml:ednotice or bml:dedication or bml:info/bml:revhistory">
			<fo:page-sequence master-reference="fm-no-page-numbered" force-page-count="no-force">
				<fo:flow flow-name="xsl-region-body">
					<xsl:apply-templates select="bml:ednotice"/>
					<xsl:apply-templates select="bml:dedication"/>
					<xsl:apply-templates select="bml:info/bml:revhistory"/>
				</fo:flow>
			</fo:page-sequence>
		</xsl:if>

		<xsl:if test="$toclevel > 0">
			<fo:page-sequence master-reference="chapter" format="i" force-page-count="no-force">
				<xsl:choose>
					<xsl:when test="$double-side = 'true'">
						<fo:static-content flow-name="chapter-first-non-blank-even-after">
							<fo:block text-align-last="justify">
								<fo:leader leader-pattern="rule"/>
							</fo:block>
							<fo:block text-align-last="justify">
								<fo:page-number/>
								<fo:leader leader-pattern="space"/>
							</fo:block>
						</fo:static-content>
						<fo:static-content flow-name="chapter-first-non-blank-odd-after">
							<fo:block text-align-last="justify">
								<fo:leader leader-pattern="rule"/>
							</fo:block>
							<fo:block text-align-last="justify">
								<fo:leader leader-pattern="space"/>
								<fo:page-number/>
							</fo:block>
						</fo:static-content>
						<fo:static-content flow-name="non-blank-even-after">
							<fo:block text-align-last="justify">
								<fo:leader leader-pattern="rule"/>
							</fo:block>
							<fo:block text-align-last="justify">
								<fo:page-number/>
								<xsl:text> | </xsl:text>
								<fo:retrieve-marker retrieve-class-name="chapter-title"/>
								<fo:leader leader-pattern="space"/>
							</fo:block>
						</fo:static-content>
						<fo:static-content flow-name="non-blank-odd-after">
							<fo:block text-align-last="justify">
								<fo:leader leader-pattern="rule"/>
							</fo:block>
							<fo:block text-align-last="justify">
								<fo:leader leader-pattern="space"/>
								<fo:retrieve-marker retrieve-class-name="chapter-title"/>
								<xsl:text> | </xsl:text>
								<fo:page-number/>
							</fo:block>
						</fo:static-content>
					</xsl:when>
					<xsl:otherwise>
						<fo:static-content flow-name="non-blank-after">
							<fo:block text-align-last="justify">
								<fo:leader leader-pattern="rule"/>
							</fo:block>
							<fo:block text-align-last="justify">
								<fo:retrieve-marker retrieve-class-name="chapter-title"/>
								<fo:leader leader-pattern="space"/>
								<fo:page-number/>
							</fo:block>
						</fo:static-content>
						<fo:static-content flow-name="chapter-first-non-blank-after">
							<fo:block text-align-last="justify">
								<fo:leader leader-pattern="rule"/>
							</fo:block>
							<fo:block text-align-last="justify">
								<fo:leader leader-pattern="space"/>
								<fo:page-number/>
							</fo:block>
						</fo:static-content>
					</xsl:otherwise>
				</xsl:choose>
				<fo:flow flow-name="xsl-region-body">
					<xsl:call-template name="put-chapter-body-start">
						<xsl:with-param name="title" select="$toc-text"/>
					</xsl:call-template>
					<xsl:apply-templates select="bml:foreword | bml:preface" mode="toc"/>
					<xsl:apply-templates select="bml:chapter" mode="toc"/>
					<xsl:apply-templates select="bml:appendix | bml:glossary | bml:index" mode="toc"
					/>
				</fo:flow>
			</fo:page-sequence>
		</xsl:if>
	</xsl:template>

	<xsl:template name="put-article-sequence">
		<fo:page-sequence master-reference="article" initial-page-number="1">
			<xsl:call-template name="put-article-static-content"/>
			<fo:flow flow-name="xsl-region-body">
				<xsl:apply-templates select="bml:info"/>
				<xsl:if test="$toclevel > 0">
					<xsl:call-template name="put-chapter-body-title">
						<xsl:with-param name="title" select="$toc-text"/>
						<xsl:with-param name="style" select="$section-title-style"/>
					</xsl:call-template>
					<xsl:apply-templates select="bml:sect1" mode="toc"/>
					<xsl:apply-templates select="bml:appendix | bml:glossary | bml:index" mode="toc"/>
					<fo:block>
						<xsl:call-template name="put-style-block-attr">
							<xsl:with-param name="style" select="$article-sect1-before-style"/>
						</xsl:call-template>
					</fo:block>
				</xsl:if>
				<xsl:apply-templates
					select="bml:*[ not( local-name() = 'appendix' ) and not( local-name() = 'glossary' ) and not( local-name() = 'index' ) and not( local-name() = 'info' ) ]"/>
				<xsl:apply-templates select="bml:appendix | bml:glossary | bml:index" mode="article"
				/>
			</fo:flow>
		</fo:page-sequence>
	</xsl:template>

	<xsl:template match="bml:appendix | bml:glossary | bml:index" mode="article">
		<xsl:if test="/bml:article">
			<fo:block>
				<xsl:call-template name="put-style-block-attr">
					<xsl:with-param name="style" select="$article-sect1-before-style"/>
				</xsl:call-template>
			</fo:block>
		</xsl:if>
		<xsl:variable name="ename" select="local-name()"/>
		<xsl:variable name="count">
			<xsl:choose>
				<xsl:when test="$ename = 'appendix'">
					<xsl:number count="bml:appendix"/>
				</xsl:when>
				<xsl:when test="$ename = 'glossary'">
					<xsl:number count="bml:glossary"/>
				</xsl:when>
				<xsl:when test="$ename = 'index'">
					<xsl:number count="bml:index"/>
				</xsl:when>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="id">
			<xsl:call-template name="put-chapter-id">
				<xsl:with-param name="count" select="$count"/>
			</xsl:call-template>
		</xsl:variable>
		<fo:block id="{$id}"/>
		<xsl:choose>
			<xsl:when test="$ename = 'appendix'">
				<xsl:call-template name="put-chapter-body-title">
					<xsl:with-param name="label">
						<xsl:call-template name="put-appendix-label">
							<xsl:with-param name="count" select="$count"/>
						</xsl:call-template>
					</xsl:with-param>
					<xsl:with-param name="title" select="bml:title"/>
					<xsl:with-param name="style" select="$section-title-style"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="put-chapter-body-title">
					<xsl:with-param name="title">
						<xsl:choose>
							<xsl:when test="$ename = 'glossary'">
								<xsl:value-of select="$glossary-text"/>
							</xsl:when>
							<xsl:when test="$ename = 'index'">
								<xsl:value-of select="$index-text"/>
							</xsl:when>
						</xsl:choose>
					</xsl:with-param>
					<xsl:with-param name="style" select="$section-title-style"/>
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:apply-templates/>
	</xsl:template>

	<xsl:template name="put-region-body">
		<xsl:param name="column" select="1"/>
		<fo:region-body column-count="{$column}">
			<xsl:for-each select="$body-region/@*">
				<xsl:choose>
					<xsl:when test="name() = 'name'"/>
					<xsl:otherwise>
						<xsl:copy/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:for-each>
			<xsl:call-template name="put-draft-image"/>
		</fo:region-body>
	</xsl:template>

	<xsl:template name="put-region-attr">
		<xsl:param name="region"/>
		<xsl:for-each select="$region/@*">
			<xsl:choose>
				<xsl:when test="name() = 'name'"/>
				<xsl:otherwise>
					<xsl:copy/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
	</xsl:template>

	<xsl:template name="put-book-layout-master-set">
		<fo:layout-master-set>
			<fo:simple-page-master master-name="fm-title" page-height="{$page-height}"
				page-width="{$page-width}" margin-top="{$margin-top}"
				margin-bottom="{$margin-bottom}" margin-left="{$margin-left}"
				margin-right="{$margin-right}">
				<xsl:call-template name="put-region-body"/>
				<fo:region-after region-name="title-after" extent="3cm"/>
			</fo:simple-page-master>
			<fo:simple-page-master master-name="fm-no-page-numbered" page-height="{$page-height}"
				page-width="{$page-width}" margin-top="{$margin-top}"
				margin-bottom="{$margin-bottom}" margin-left="{$margin-left}"
				margin-right="{$margin-right}">
				<xsl:call-template name="put-region-body"/>
			</fo:simple-page-master>
			<xsl:choose>
				<xsl:when test="$double-side = 'true'">
					<xsl:call-template name="put-double-side-page-master">
						<xsl:with-param name="target">chapter</xsl:with-param>
						<xsl:with-param name="column">1</xsl:with-param>
					</xsl:call-template>
					<xsl:call-template name="put-double-side-page-master">
						<xsl:with-param name="target">twocol</xsl:with-param>
						<xsl:with-param name="column">2</xsl:with-param>
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="put-single-page-master">
						<xsl:with-param name="target">chapter</xsl:with-param>
						<xsl:with-param name="column">1</xsl:with-param>
					</xsl:call-template>
					<xsl:call-template name="put-single-page-master">
						<xsl:with-param name="target">twocol</xsl:with-param>
						<xsl:with-param name="column">2</xsl:with-param>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
			<fo:simple-page-master master-name="book-blank" page-height="{$page-height}"
				page-width="{$page-width}" margin-top="{$margin-top}"
				margin-bottom="{$margin-bottom}" margin-left="{$margin-left}"
				margin-right="{$margin-right}">
				<xsl:call-template name="put-region-body"/>
				<fo:region-before region-name="blank-before">
					<xsl:call-template name="put-region-attr">
						<xsl:with-param name="region" select="$before-region"/>
					</xsl:call-template>
				</fo:region-before>
				<fo:region-after region-name="blank-after">
					<xsl:call-template name="put-region-attr">
						<xsl:with-param name="region" select="$after-region"/>
					</xsl:call-template>
				</fo:region-after>
			</fo:simple-page-master>
			<fo:page-sequence-master master-name="chapter" force-page-count="no-force">
				<xsl:choose>
					<xsl:when test="$double-side = 'true'">
						<fo:repeatable-page-master-alternatives>
							<fo:conditional-page-master-reference
								master-reference="book-odd-chapter-first" page-position="first"
								odd-or-even="odd"/>
							<fo:conditional-page-master-reference
								master-reference="book-even-chapter-first" page-position="first"
								odd-or-even="even"/>
							<fo:conditional-page-master-reference
								master-reference="book-odd-chapter" page-position="any"
								odd-or-even="odd"/>
							<fo:conditional-page-master-reference
								master-reference="book-even-chapter" page-position="any"
								odd-or-even="even"/>
							<!--<fo:conditional-page-master-reference master-reference="book-last-even" page-position="last"
								odd-or-even="even"/>-->
							<fo:conditional-page-master-reference master-reference="book-blank"
								blank-or-not-blank="blank"/>
						</fo:repeatable-page-master-alternatives>
					</xsl:when>
					<xsl:otherwise>
						<fo:repeatable-page-master-alternatives>
							<fo:conditional-page-master-reference
								master-reference="book-single-chapter-first" page-position="first"/>
							<fo:conditional-page-master-reference
								master-reference="book-single-chapter" page-position="rest"/>
							<fo:conditional-page-master-reference master-reference="book-blank"
								blank-or-not-blank="blank"/>
						</fo:repeatable-page-master-alternatives>
					</xsl:otherwise>
				</xsl:choose>
			</fo:page-sequence-master>
			<fo:page-sequence-master master-name="twocol">
				<xsl:choose>
					<xsl:when test="$double-side = 'true'">
						<fo:repeatable-page-master-alternatives>
							<fo:conditional-page-master-reference
								master-reference="book-odd-twocol-first" page-position="first"
								odd-or-even="odd"/>
							<fo:conditional-page-master-reference
								master-reference="book-even-twocol-first" page-position="first"
								odd-or-even="even"/>
							<fo:conditional-page-master-reference master-reference="book-odd-twocol"
								page-position="any" odd-or-even="odd"/>
							<fo:conditional-page-master-reference
								master-reference="book-even-twocol" page-position="any"
								odd-or-even="even"/>
							<fo:conditional-page-master-reference master-reference="book-blank"
								blank-or-not-blank="blank"/>
						</fo:repeatable-page-master-alternatives>
					</xsl:when>
					<xsl:otherwise>
						<fo:repeatable-page-master-alternatives>
							<fo:conditional-page-master-reference
								master-reference="book-single-twocol-first" page-position="first"/>
							<fo:conditional-page-master-reference
								master-reference="book-single-twocol" page-position="rest"/>
							<fo:conditional-page-master-reference master-reference="book-blank"
								blank-or-not-blank="blank"/>
						</fo:repeatable-page-master-alternatives>
					</xsl:otherwise>
				</xsl:choose>
			</fo:page-sequence-master>
		</fo:layout-master-set>
	</xsl:template>

	<xsl:template name="put-article-layout-master-set">
		<fo:layout-master-set>
			<fo:simple-page-master master-name="article" page-height="{$page-height}"
				page-width="{$page-width}" margin-top="{$margin-top}"
				margin-bottom="{$margin-bottom}" margin-left="{$margin-left}"
				margin-right="{$margin-right}">
				<xsl:call-template name="put-region-body"/>
				<fo:region-before region-name="non-blank-before">
					<xsl:call-template name="put-region-attr">
						<xsl:with-param name="region" select="$before-region"/>
					</xsl:call-template>
				</fo:region-before>
				<fo:region-after region-name="non-blank-after">
					<xsl:call-template name="put-region-attr">
						<xsl:with-param name="region" select="$after-region"/>
					</xsl:call-template>
				</fo:region-after>
			</fo:simple-page-master>
		</fo:layout-master-set>
	</xsl:template>

	<xsl:template name="put-single-page-master">
		<xsl:param name="target"/>
		<xsl:param name="column"/>
		<fo:simple-page-master master-name="book-single-{$target}-first"
			page-height="{$page-height}" page-width="{$page-width}" margin-top="{$margin-top}"
			margin-bottom="{$margin-bottom}" margin-left="{$margin-left}"
			margin-right="{$margin-right}">
			<xsl:call-template name="put-region-body">
				<xsl:with-param name="column" select="$column"/>
			</xsl:call-template>
			<fo:region-before region-name="chapter-first-non-blank-before">
				<xsl:call-template name="put-region-attr">
					<xsl:with-param name="region" select="$before-region"/>
				</xsl:call-template>
			</fo:region-before>
			<fo:region-after region-name="chapter-first-non-blank-after">
				<xsl:call-template name="put-region-attr">
					<xsl:with-param name="region" select="$after-region"/>
				</xsl:call-template>
			</fo:region-after>
		</fo:simple-page-master>
		<fo:simple-page-master master-name="book-single-{$target}" page-height="{$page-height}"
			page-width="{$page-width}" margin-top="{$margin-top}" margin-bottom="{$margin-bottom}"
			margin-left="{$margin-left}" margin-right="{$margin-right}">
			<xsl:call-template name="put-region-body">
				<xsl:with-param name="column" select="$column"/>
			</xsl:call-template>
			<fo:region-before region-name="non-blank-before">
				<xsl:call-template name="put-region-attr">
					<xsl:with-param name="region" select="$before-region"/>
				</xsl:call-template>
			</fo:region-before>
			<fo:region-after region-name="non-blank-after">
				<xsl:call-template name="put-region-attr">
					<xsl:with-param name="region" select="$after-region"/>
				</xsl:call-template>
			</fo:region-after>
		</fo:simple-page-master>
		<fo:simple-page-master master-name="book-last-{$target}" page-height="{$page-height}"
			page-width="{$page-width}" margin-top="{$margin-top}" margin-bottom="{$margin-bottom}"
			margin-left="{$margin-left}" margin-right="{$margin-right}">
			<xsl:call-template name="put-region-body">
				<xsl:with-param name="column" select="$column"/>
			</xsl:call-template>
			<fo:region-before region-name="last-before">
				<xsl:call-template name="put-region-attr">
					<xsl:with-param name="region" select="$before-region"/>
				</xsl:call-template>
			</fo:region-before>
			<fo:region-after region-name="last-after">
				<xsl:call-template name="put-region-attr">
					<xsl:with-param name="region" select="$after-region"/>
				</xsl:call-template>
			</fo:region-after>
		</fo:simple-page-master>
	</xsl:template>

	<xsl:template name="put-double-side-page-master">
		<xsl:param name="target"/>
		<xsl:param name="column"/>
		<fo:simple-page-master master-name="book-odd-{$target}-first" page-height="{$page-height}"
			page-width="{$page-width}" margin-top="{$margin-top}" margin-bottom="{$margin-bottom}"
			margin-left="{$odd-margin-left}" margin-right="{$odd-margin-right}">
			<xsl:call-template name="put-region-body">
				<xsl:with-param name="column" select="$column"/>
			</xsl:call-template>
			<fo:region-before region-name="chapter-first-non-blank-odd-before">
				<xsl:call-template name="put-region-attr">
					<xsl:with-param name="region" select="$before-region"/>
				</xsl:call-template>
			</fo:region-before>
			<fo:region-after region-name="chapter-first-non-blank-odd-after">
				<xsl:call-template name="put-region-attr">
					<xsl:with-param name="region" select="$after-region"/>
				</xsl:call-template>
			</fo:region-after>
		</fo:simple-page-master>
		<fo:simple-page-master master-name="book-even-{$target}-first" page-height="{$page-height}"
			page-width="{$page-width}" margin-top="{$margin-top}" margin-bottom="{$margin-bottom}"
			margin-left="{$even-margin-left}" margin-right="{$even-margin-right}">
			<xsl:call-template name="put-region-body">
				<xsl:with-param name="column" select="$column"/>
			</xsl:call-template>
			<fo:region-before region-name="chapter-first-non-blank-even-before">
				<xsl:call-template name="put-region-attr">
					<xsl:with-param name="region" select="$before-region"/>
				</xsl:call-template>
			</fo:region-before>
			<fo:region-after region-name="chapter-first-non-blank-even-after">
				<xsl:call-template name="put-region-attr">
					<xsl:with-param name="region" select="$after-region"/>
				</xsl:call-template>
			</fo:region-after>
		</fo:simple-page-master>
		<fo:simple-page-master master-name="book-odd-{$target}" page-height="{$page-height}"
			page-width="{$page-width}" margin-top="{$margin-top}" margin-bottom="{$margin-bottom}"
			margin-left="{$odd-margin-left}" margin-right="{$odd-margin-right}">
			<xsl:call-template name="put-region-body">
				<xsl:with-param name="column" select="$column"/>
			</xsl:call-template>
			<fo:region-before region-name="non-blank-odd-before">
				<xsl:call-template name="put-region-attr">
					<xsl:with-param name="region" select="$before-region"/>
				</xsl:call-template>
			</fo:region-before>
			<fo:region-after region-name="non-blank-odd-after">
				<xsl:call-template name="put-region-attr">
					<xsl:with-param name="region" select="$after-region"/>
				</xsl:call-template>
			</fo:region-after>
		</fo:simple-page-master>
		<fo:simple-page-master master-name="book-even-{$target}" page-height="{$page-height}"
			page-width="{$page-width}" margin-top="{$margin-top}" margin-bottom="{$margin-bottom}"
			margin-left="{$even-margin-left}" margin-right="{$even-margin-right}">
			<xsl:call-template name="put-region-body">
				<xsl:with-param name="column" select="$column"/>
			</xsl:call-template>
			<fo:region-before region-name="non-blank-even-before">
				<xsl:call-template name="put-region-attr">
					<xsl:with-param name="region" select="$before-region"/>
				</xsl:call-template>
			</fo:region-before>
			<fo:region-after region-name="non-blank-even-after">
				<xsl:call-template name="put-region-attr">
					<xsl:with-param name="region" select="$after-region"/>
				</xsl:call-template>
			</fo:region-after>
		</fo:simple-page-master>
		<fo:simple-page-master master-name="book-last-even-{$target}" page-height="{$page-height}"
			page-width="{$page-width}" margin-top="{$margin-top}" margin-bottom="{$margin-bottom}"
			margin-left="{$even-margin-left}" margin-right="{$even-margin-right}">
			<xsl:call-template name="put-region-body">
				<xsl:with-param name="column" select="$column"/>
			</xsl:call-template>
			<fo:region-before region-name="last-before">
				<xsl:call-template name="put-region-attr">
					<xsl:with-param name="region" select="$before-region"/>
				</xsl:call-template>
			</fo:region-before>
			<fo:region-after region-name="last-after">
				<xsl:call-template name="put-region-attr">
					<xsl:with-param name="region" select="$after-region"/>
				</xsl:call-template>
			</fo:region-after>
		</fo:simple-page-master>
	</xsl:template>

	<xsl:template match="bml:foreword" mode="toc">
		<xsl:variable name="name" select="local-name()"/>
		<xsl:variable name="text" select="$foreword-text"/>
		<xsl:variable name="id">
			<xsl:call-template name="put-chapter-id">
				<xsl:with-param name="count">
					<xsl:number count="bml:foreword"/>
				</xsl:with-param>
			</xsl:call-template>
		</xsl:variable>
		<xsl:call-template name="put-toc-chapter-body">
			<xsl:with-param name="id" select="$id"/>
			<xsl:with-param name="text" select="$text"/>
		</xsl:call-template>
	</xsl:template>

	<xsl:template match="bml:preface" mode="toc">
		<xsl:variable name="name" select="local-name()"/>
		<xsl:variable name="text" select="$preface-text"/>
		<xsl:variable name="id">
			<xsl:call-template name="put-chapter-id">
				<xsl:with-param name="count">
					<xsl:number count="bml:preface"/>
				</xsl:with-param>
			</xsl:call-template>
		</xsl:variable>
		<xsl:call-template name="put-toc-chapter-body">
			<xsl:with-param name="id" select="$id"/>
			<xsl:with-param name="text" select="$text"/>
		</xsl:call-template>
	</xsl:template>

	<xsl:template match="bml:appendix" mode="toc">
		<xsl:variable name="name" select="local-name()"/>
		<xsl:variable name="text">
			<xsl:call-template name="put-appendix-label">
				<xsl:with-param name="count">
					<xsl:number count="bml:appendix"/>
				</xsl:with-param>
			</xsl:call-template>
			<xsl:text>. </xsl:text>
			<xsl:value-of select="bml:title"/>
		</xsl:variable>
		<xsl:variable name="id">
			<xsl:call-template name="put-chapter-id">
				<xsl:with-param name="count">
					<xsl:number count="bml:appendix"/>
				</xsl:with-param>
			</xsl:call-template>
		</xsl:variable>
		<xsl:call-template name="put-toc-chapter-body">
			<xsl:with-param name="id" select="$id"/>
			<xsl:with-param name="text" select="$text"/>
		</xsl:call-template>
		<xsl:if test="$toclevel > 1">
			<xsl:apply-templates select="bml:sect1" mode="toc"/>
		</xsl:if>
	</xsl:template>

	<xsl:template match="bml:glossary" mode="toc">
		<xsl:variable name="name" select="local-name()"/>
		<xsl:variable name="text" select="$glossary-text"/>
		<xsl:variable name="id">
			<xsl:call-template name="put-chapter-id">
				<xsl:with-param name="count">
					<xsl:number count="bml:glossary"/>
				</xsl:with-param>
			</xsl:call-template>
		</xsl:variable>
		<xsl:call-template name="put-toc-chapter-body">
			<xsl:with-param name="id" select="$id"/>
			<xsl:with-param name="text" select="$text"/>
		</xsl:call-template>
	</xsl:template>

	<xsl:template match="bml:index" mode="toc">
		<xsl:variable name="name" select="local-name()"/>
		<xsl:variable name="text" select="$index-text"/>
		<xsl:variable name="id">
			<xsl:call-template name="put-chapter-id">
				<xsl:with-param name="count">
					<xsl:number count="bml:index"/>
				</xsl:with-param>
			</xsl:call-template>
		</xsl:variable>
		<xsl:call-template name="put-toc-chapter-body">
			<xsl:with-param name="id" select="$id"/>
			<xsl:with-param name="text" select="$text"/>
		</xsl:call-template>
	</xsl:template>

	<xsl:template name="put-toc-chapter-body">
		<xsl:param name="id"/>
		<xsl:param name="text"/>
		<fo:block text-align-last="justify">
			<xsl:choose>
				<xsl:when test="/bml:book">
					<xsl:call-template name="put-style-block-attr">
						<xsl:with-param name="style" select="$book-toc-chapter-style"/>
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="put-style-block-attr">
						<xsl:with-param name="style" select="$article-toc-chapter-style"/>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
			<fo:basic-link>
				<xsl:attribute name="internal-destination">
					<xsl:value-of select="$id"/>
				</xsl:attribute>
				<xsl:value-of select="$text"/>
			</fo:basic-link>
			<fo:inline keep-together.within-line="always">
				<fo:leader leader-pattern="dots"/>
				<fo:basic-link>
					<xsl:attribute name="internal-destination">
						<xsl:value-of select="$id"/>
					</xsl:attribute>
					<fo:page-number-citation>
						<xsl:attribute name="ref-id">
							<xsl:value-of select="$id"/>
						</xsl:attribute>
					</fo:page-number-citation>
				</fo:basic-link>
			</fo:inline>
		</fo:block>
	</xsl:template>

	<xsl:template name="put-id-attr">
		<xsl:if test="@xml:id">
			<xsl:attribute name="id">
				<xsl:value-of select="@xml:id"/>
			</xsl:attribute>
		</xsl:if>
	</xsl:template>

	<xsl:template name="put-id-attr-block">
		<xsl:if test="@xml:id">
			<fo:block>
				<xsl:attribute name="id">
					<xsl:value-of select="@xml:id"/>
				</xsl:attribute>
			</fo:block>
		</xsl:if>
	</xsl:template>

	<xsl:template match="bml:chapter" mode="toc">
		<xsl:variable name="name" select="local-name()"/>
		<xsl:variable name="count">
			<xsl:number count="bml:chapter"/>
		</xsl:variable>
		<xsl:variable name="text">
			<xsl:value-of
				select="concat( substring-before( $chapter-text, '%n' ), $count, substring-after( $chapter-text, '%n' ) )"/>
			<xsl:text>. </xsl:text>
			<xsl:value-of select="bml:title"/>
		</xsl:variable>
		<xsl:variable name="id">
			<xsl:call-template name="put-chapter-id">
				<xsl:with-param name="count" select="$count"/>
			</xsl:call-template>
		</xsl:variable>
		<fo:block>
			<xsl:choose>
				<xsl:when test="/bml:book">
					<xsl:if test="$book-toc-chapter-style/@margin-left">
						<xsl:attribute name="margin-left">
							<xsl:value-of select="$book-toc-chapter-style/@margin-left"/>
						</xsl:attribute>
					</xsl:if>
				</xsl:when>
				<xsl:otherwise>
					<xsl:if test="$article-toc-chapter-style/@margin-left">
						<xsl:attribute name="margin-left">
							<xsl:value-of select="$article-toc-chapter-style/@margin-left"/>
						</xsl:attribute>
					</xsl:if>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:call-template name="put-toc-chapter-body">
				<xsl:with-param name="id" select="$id"/>
				<xsl:with-param name="text" select="$text"/>
			</xsl:call-template>
		</fo:block>
		<xsl:if test="$toclevel > 1">
			<xsl:apply-templates select="bml:sect1" mode="toc"/>
		</xsl:if>
	</xsl:template>

	<xsl:template match="bml:sect1" mode="toc">
		<xsl:variable name="chapid">
			<xsl:call-template name="put-chapter-id"/>
		</xsl:variable>
		<xsl:variable name="sect1count">
			<xsl:number count="bml:sect1"/>
		</xsl:variable>
		<xsl:variable name="sect1id" select="concat( $chapid, '-sect1-', $sect1count )"/>
		<xsl:if test="bml:title">
			<xsl:choose>
				<xsl:when test="/bml:book">
					<xsl:call-template name="put-sect-toc">
						<xsl:with-param name="id" select="$sect1id"/>
						<xsl:with-param name="style" select="$book-toc-section1-style"/>
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="put-sect-toc">
						<xsl:with-param name="id" select="$sect1id"/>
						<xsl:with-param name="style" select="$article-toc-section1-style"/>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:if>
		<xsl:choose>
			<xsl:when test="/bml:book">
				<xsl:if test="$toclevel > 2">
					<xsl:apply-templates select="bml:sect2" mode="toc">
						<xsl:with-param name="sect1id" select="$sect1id"/>
					</xsl:apply-templates>
				</xsl:if>
			</xsl:when>
			<xsl:otherwise>
				<xsl:if test="$toclevel > 1">
					<xsl:apply-templates select="bml:sect2" mode="toc">
						<xsl:with-param name="sect1id" select="$sect1id"/>
					</xsl:apply-templates>
				</xsl:if>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="bml:sect2" mode="toc">
		<xsl:param name="sect1id"/>
		<xsl:variable name="sect2count">
			<xsl:number count="bml:sect2"/>
		</xsl:variable>
		<xsl:variable name="sect2id" select="concat( $sect1id, '-sect2-', $sect2count )"/>
		<xsl:if test="bml:title">
			<xsl:choose>
				<xsl:when test="/bml:book">
					<xsl:call-template name="put-sect-toc">
						<xsl:with-param name="id" select="$sect2id"/>
						<xsl:with-param name="style" select="$book-toc-section2-style"/>
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="put-sect-toc">
						<xsl:with-param name="id" select="$sect2id"/>
						<xsl:with-param name="style" select="$article-toc-section2-style"/>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:if>
	</xsl:template>

	<xsl:template name="put-sect-toc">
		<xsl:param name="id"/>
		<xsl:param name="style"/>
		<fo:block>
			<xsl:if test="$style/@margin-left">
				<xsl:attribute name="margin-left">
					<xsl:value-of select="$style/@margin-left"/>
				</xsl:attribute>
			</xsl:if>
			<fo:block text-align-last="justify">
				<xsl:call-template name="put-style-block-attr">
					<xsl:with-param name="style" select="$style"/>
				</xsl:call-template>
				<fo:basic-link>
					<xsl:attribute name="internal-destination">
						<xsl:value-of select="$id"/>
					</xsl:attribute>
					<xsl:value-of select="bml:title"/>
				</fo:basic-link>
				<fo:inline keep-together.within-line="always">
					<fo:leader leader-pattern="dots"/>
					<fo:basic-link>
						<xsl:attribute name="internal-destination">
							<xsl:value-of select="$id"/>
						</xsl:attribute>
						<fo:page-number-citation>
							<xsl:attribute name="ref-id">
								<xsl:value-of select="$id"/>
							</xsl:attribute>
						</fo:page-number-citation>
					</fo:basic-link>
				</fo:inline>
			</fo:block>
		</fo:block>
	</xsl:template>

	<xsl:template
		match="/bml:foreword | /bml:preface | /bml:chapter | /bml:appendix | /bml:glossary | /bml:index">
		<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
			<xsl:call-template name="put-style-block-attr">
				<xsl:with-param name="style" select="$root-style"/>
			</xsl:call-template>
			<xsl:call-template name="put-book-layout-master-set"/>
			<xsl:call-template name="put-chapter"/>
		</fo:root>
	</xsl:template>

	<xsl:template
		match="bml:foreword | bml:preface | bml:chapter | bml:appendix | bml:glossary | bml:index">
		<xsl:call-template name="put-chapter"/>
	</xsl:template>

	<xsl:template name="put-chapter">
		<xsl:variable name="ename" select="local-name()"/>
		<xsl:variable name="count">
			<xsl:choose>
				<xsl:when test="$ename = 'chapter'">
					<xsl:number count="bml:chapter"/>
				</xsl:when>
				<xsl:when test="$ename = 'appendix'">
					<xsl:number count="bml:appendix"/>
				</xsl:when>
				<xsl:when test="$ename = 'foreword'">
					<xsl:number count="bml:foreword"/>
				</xsl:when>
				<xsl:when test="$ename = 'preface'">
					<xsl:number count="bml:preface"/>
				</xsl:when>
				<xsl:when test="$ename = 'glossary'">
					<xsl:number count="bml:glossary"/>
				</xsl:when>
				<xsl:when test="$ename = 'index'">
					<xsl:number count="bml:index"/>
				</xsl:when>
			</xsl:choose>
		</xsl:variable>
		<fo:page-sequence force-page-count="no-force">
			<xsl:choose>
				<xsl:when test="$ename = 'index' or $ename = 'glossary'">
					<xsl:attribute name="master-reference">twocol</xsl:attribute>
				</xsl:when>
				<xsl:otherwise>
					<xsl:attribute name="master-reference">chapter</xsl:attribute>
				</xsl:otherwise>
			</xsl:choose>
			<!-- reset page number at the first chapter -->
			<xsl:if test="$ename = 'chapter' and $count = 1">
				<xsl:attribute name="initial-page-number">1</xsl:attribute>
			</xsl:if>
			<xsl:if test="$ename = 'foreword' or $ename = 'preface'">
				<xsl:attribute name="format">i</xsl:attribute>
			</xsl:if>
			<xsl:call-template name="put-chapter-static-content"/>
			<fo:flow flow-name="xsl-region-body">
				<xsl:choose>
					<xsl:when test="$ename = 'chapter'">
						<xsl:call-template name="put-chapter-body">
							<xsl:with-param name="count" select="$count"/>
							<xsl:with-param name="label">
								<xsl:value-of
									select="concat( substring-before( $chapter-text, '%n' ), $count, substring-after( $chapter-text, '%n' ) )"
								/>
							</xsl:with-param>
							<xsl:with-param name="title" select="bml:title"/>
						</xsl:call-template>
					</xsl:when>
					<xsl:when test="$ename = 'appendix'">
						<xsl:call-template name="put-chapter-body">
							<xsl:with-param name="count" select="$count"/>
							<xsl:with-param name="label">
								<xsl:call-template name="put-appendix-label">
									<xsl:with-param name="count" select="$count"/>
								</xsl:call-template>
							</xsl:with-param>
							<xsl:with-param name="title" select="bml:title"/>
						</xsl:call-template>
					</xsl:when>
					<xsl:otherwise>
						<xsl:call-template name="put-chapter-body">
							<xsl:with-param name="title">
								<xsl:choose>
									<xsl:when test="$ename = 'revhistory'">
										<xsl:value-of select="$revhistory-text"/>
									</xsl:when>
									<xsl:when test="$ename = 'foreword'">
										<xsl:value-of select="$foreword-text"/>
									</xsl:when>
									<xsl:when test="$ename = 'preface'">
										<xsl:value-of select="$preface-text"/>
									</xsl:when>
									<xsl:when test="$ename = 'glossary'">
										<xsl:value-of select="$glossary-text"/>
									</xsl:when>
									<xsl:when test="$ename = 'index'">
										<xsl:value-of select="$index-text"/>
									</xsl:when>
								</xsl:choose>
							</xsl:with-param>
						</xsl:call-template>
					</xsl:otherwise>
				</xsl:choose>
			</fo:flow>
		</fo:page-sequence>
	</xsl:template>

	<xsl:template name="put-article-static-content">
		<fo:static-content flow-name="xsl-footnote-separator">
			<fo:block>
				<fo:block text-align-last="justify">
					<fo:leader leader-pattern="dots"/>
				</fo:block>
			</fo:block>
		</fo:static-content>
		<fo:static-content flow-name="non-blank-before">
			<fo:block/>
		</fo:static-content>
		<fo:static-content flow-name="non-blank-after">
			<fo:block text-align-last="justify">
				<fo:leader leader-pattern="rule"/>
			</fo:block>
			<fo:block text-align-last="justify">
				<fo:retrieve-marker retrieve-class-name="article-title"/>
				<fo:leader leader-pattern="space"/>
				<fo:retrieve-marker retrieve-class-name="sect1-title"/>
				<xsl:text> | </xsl:text>
				<fo:page-number/>
			</fo:block>
		</fo:static-content>
	</xsl:template>

	<xsl:template name="put-chapter-static-content">
		<fo:static-content flow-name="blank-after">
			<fo:block>blank-after <fo:page-number/></fo:block>
		</fo:static-content>
		<fo:static-content flow-name="xsl-footnote-separator">
			<fo:block>
				<fo:block text-align-last="justify">
					<fo:leader leader-pattern="dots"/>
				</fo:block>
			</fo:block>
		</fo:static-content>
		<xsl:choose>
			<xsl:when test="$double-side = 'true'">
				<fo:static-content flow-name="non-blank-even-after">
					<fo:block text-align-last="justify">
						<fo:leader leader-pattern="rule"/>
					</fo:block>
					<fo:block text-align-last="justify">
						<fo:page-number/>
						<xsl:text> | </xsl:text>
						<fo:retrieve-marker retrieve-class-name="chapter-label"/>
						<fo:retrieve-marker retrieve-class-name="chapter-title"/>
						<fo:leader leader-pattern="space"/>
					</fo:block>
				</fo:static-content>
				<fo:static-content flow-name="non-blank-odd-before">
					<fo:block/>
				</fo:static-content>
				<fo:static-content flow-name="non-blank-odd-after">
					<fo:block text-align-last="justify">
						<fo:leader leader-pattern="rule"/>
					</fo:block>
					<fo:block text-align-last="justify">
						<fo:leader leader-pattern="space"/>
						<fo:retrieve-marker retrieve-class-name="sect1-title"/>
						<xsl:text> | </xsl:text>
						<fo:page-number/>
					</fo:block>
				</fo:static-content>
				<fo:static-content flow-name="chapter-first-non-blank-even-before">
					<fo:block/>
				</fo:static-content>
				<fo:static-content flow-name="chapter-first-non-blank-even-after">
					<fo:block text-align-last="justify">
						<fo:leader leader-pattern="rule"/>
					</fo:block>
					<fo:block text-align-last="justify">
						<fo:page-number/>
						<fo:leader leader-pattern="space"/>
					</fo:block>
				</fo:static-content>
				<fo:static-content flow-name="chapter-first-non-blank-odd-before">
					<fo:block/>
				</fo:static-content>
				<fo:static-content flow-name="chapter-first-non-blank-odd-after">
					<fo:block text-align-last="justify">
						<fo:leader leader-pattern="rule"/>
					</fo:block>
					<fo:block text-align-last="justify">
						<fo:leader leader-pattern="space"/>
						<fo:page-number/>
					</fo:block>
				</fo:static-content>
			</xsl:when>
			<xsl:otherwise>
				<fo:static-content flow-name="non-blank-before">
					<fo:block/>
				</fo:static-content>
				<fo:static-content flow-name="non-blank-after">
					<fo:block text-align-last="justify">
						<fo:leader leader-pattern="rule"/>
					</fo:block>
					<fo:block text-align-last="justify">
						<fo:retrieve-marker retrieve-class-name="chapter-label"/>
						<fo:retrieve-marker retrieve-class-name="chapter-title"/>
						<fo:leader leader-pattern="space"/>
						<fo:retrieve-marker retrieve-class-name="sect1-title"/>
						<xsl:text> | </xsl:text>
						<fo:page-number/>
					</fo:block>
				</fo:static-content>
				<fo:static-content flow-name="chapter-first-non-blank-before">
					<fo:block/>
				</fo:static-content>
				<fo:static-content flow-name="chapter-first-non-blank-after">
					<fo:block text-align-last="justify">
						<fo:leader leader-pattern="rule"/>
					</fo:block>
					<fo:block text-align-last="justify">
						<fo:leader leader-pattern="space"/>
						<fo:page-number/>
					</fo:block>
				</fo:static-content>
			</xsl:otherwise>
		</xsl:choose>
		<fo:static-content flow-name="last-before">
			<fo:block/>
		</fo:static-content>
		<fo:static-content flow-name="last-after">
			<fo:block>last-after <fo:page-number/></fo:block>
		</fo:static-content>
	</xsl:template>

	<xsl:template name="put-appendix-label">
		<xsl:param name="count"/>
		<xsl:value-of
			select="concat( substring-before( $appendix-text, '%n' ), translate( $count, '123456789', 'ABCDEFGHIJ'), 
			substring-after( $appendix-text, '%n' ) )"
		/>
	</xsl:template>

	<xsl:template name="put-chapter-body">
		<xsl:param name="label"/>
		<xsl:param name="title"/>
		<xsl:param name="count"/>
		<xsl:variable name="chapid">
			<xsl:call-template name="put-chapter-id"/>
		</xsl:variable>
		<xsl:call-template name="put-chapter-body-start">
			<xsl:with-param name="chapid" select="$chapid"/>
			<xsl:with-param name="label" select="$label"/>
			<xsl:with-param name="title" select="$title"/>
		</xsl:call-template>
		<xsl:choose>
			<xsl:when test="local-name() = 'glossary'">
				<xsl:apply-templates select="//bml:glodiv">
					<xsl:sort select="bml:title"/>
				</xsl:apply-templates>
				<xsl:apply-templates select="//bml:gloentry">
					<xsl:sort select="bml:gloterm"/>
				</xsl:apply-templates>
			</xsl:when>
			<xsl:when test="local-name() = 'index'">
				<xsl:apply-templates select="//bml:indexterm" mode="index">
					<xsl:sort select="bml:primary"/>
				</xsl:apply-templates>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates>
					<xsl:with-param name="chapid" select="$chapid"/>
				</xsl:apply-templates>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template name="put-chapter-body-start">
		<xsl:param name="label"/>
		<xsl:param name="title"/>
		<xsl:variable name="chapid">
			<xsl:call-template name="put-chapter-id"/>
		</xsl:variable>
		<fo:block span="all" break-before="page">
			<xsl:if test="$chapid">
				<xsl:attribute name="id">
					<xsl:value-of select="$chapid"/>
				</xsl:attribute>
			</xsl:if>
			<xsl:call-template name="put-book-chapter-title-label">
				<xsl:with-param name="label" select="$label"/>
				<xsl:with-param name="title" select="$title"/>
			</xsl:call-template>
			<xsl:call-template name="put-chapter-body-title">
				<xsl:with-param name="title" select="$title"/>
				<xsl:with-param name="style" select="$book-chapter-title-style"/>
			</xsl:call-template>
		</fo:block>
	</xsl:template>

	<xsl:template name="put-book-chapter-title-label">
		<xsl:param name="label"/>
		<xsl:param name="title"/>
		<fo:marker marker-class-name="chapter-label">
			<xsl:if test="$label">
				<xsl:value-of select="$label"/>
				<xsl:text>:</xsl:text>
			</xsl:if>
		</fo:marker>
		<fo:marker marker-class-name="sect1-title"/>
		<fo:marker marker-class-name="chapter-title">
			<xsl:value-of select="$title"/>
		</fo:marker>
		<fo:block>
			<xsl:call-template name="put-id-attr"/>
			<xsl:call-template name="put-chapter-body-title">
				<xsl:with-param name="title" select="$label"/>
				<xsl:with-param name="font-size">80%</xsl:with-param>
				<xsl:with-param name="style" select="$book-chapter-title-style"/>
			</xsl:call-template>
		</fo:block>
		<fo:block text-align-last="justify">
			<fo:leader leader-pattern="rule"/>
		</fo:block>
	</xsl:template>

	<xsl:template name="put-chapter-body-title">
		<xsl:param name="title"/>
		<xsl:param name="font-size"/>
		<xsl:param name="style"/>
		<xsl:param name="label"/>
		<fo:block>
			<xsl:for-each select="$style/@*">
				<xsl:variable name="name" select="local-name()"/>
				<xsl:choose>
					<xsl:when test="$name = 'name'"/>
					<xsl:when test="$name = 'margin-bottom'"/>
					<xsl:when test="$name = 'font-family'">
						<xsl:call-template name="put-font-family-attr">
							<xsl:with-param name="style" select="$style"/>
						</xsl:call-template>
					</xsl:when>
					<xsl:otherwise>
						<xsl:copy/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:for-each>
			<xsl:if test="/bml:article and string-length($label) > 0">
				<xsl:value-of select="$label"/>
				<xsl:text>. </xsl:text>
			</xsl:if>
			<xsl:choose>
				<xsl:when test="$font-size">
					<fo:block font-size="{$font-size}">
						<xsl:call-template name="put-chapter-body-title-text">
							<xsl:with-param name="text" select="$title"/>
						</xsl:call-template>
					</fo:block>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="put-chapter-body-title-text">
						<xsl:with-param name="text" select="$title"/>
					</xsl:call-template>
					<xsl:if test="$style/@margin-bottom">
						<fo:block>
							<xsl:attribute name="margin-bottom">
								<xsl:value-of select="$style/@margin-bottom"/>
							</xsl:attribute>
						</fo:block>
					</xsl:if>
				</xsl:otherwise>
			</xsl:choose>
		</fo:block>
	</xsl:template>

	<xsl:template name="put-chapter-body-title-text">
		<xsl:param name="text"/>
		<xsl:choose>
			<xsl:when test="string-length(normalize-space($text))">
				<xsl:value-of select="$text"/>
			</xsl:when>
			<xsl:otherwise>
				<fo:leader leader-pattern="space"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template name="put-footnote-count">
		<xsl:param name="id"/>
		<xsl:choose>
			<xsl:when test="/bml:book">
				<xsl:for-each
					select="(ancestor::*[ local-name() = 'foreword' or local-name() = 'preface' or local-name() = 'chapter' or local-name() = 'appendix' or local-name() = 'glossary' or local-name() = 'index' ])[1]">
					<xsl:for-each select=".//bml:footnote">
						<xsl:if test="generate-id(.) = $id">
							<xsl:value-of select="position()"/>
						</xsl:if>
					</xsl:for-each>
				</xsl:for-each>
			</xsl:when>
			<xsl:otherwise>
				<xsl:for-each select="//bml:footnote">
					<xsl:if test="generate-id(.) = $id">
						<xsl:value-of select="position()"/>
					</xsl:if>
				</xsl:for-each>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="bml:emphasis">
		<xsl:call-template name="put-id-attr-block"/>
		<fo:inline>
			<xsl:choose>
				<xsl:when test="@deco = 'underline'">
					<xsl:attribute name="text-decoration">underline</xsl:attribute>
				</xsl:when>
				<xsl:when test="@deco = 'strike'">
					<xsl:attribute name="text-decoration">line-through</xsl:attribute>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="put-style-block-attr">
						<xsl:with-param name="style" select="$emphasis-style"/>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:value-of select="."/>
		</fo:inline>
	</xsl:template>

	<xsl:template match="bml:footnote">
		<xsl:choose>
			<xsl:when
				test="ancestor-or-self::bml:ulist | ancestor-or-self::bml:olist | ancestor-or-self::bml:table | ancestor-or-self::bml:note | ancestor-or-self::bml:warning | ancestor-or-self::bml:important">
				<xsl:variable name="count">
					<xsl:call-template name="put-footnote-count">
						<xsl:with-param name="id" select="generate-id(.)"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:variable name="id">
					<xsl:call-template name="put-footnote-id">
						<xsl:with-param name="count" select="$count"/>
					</xsl:call-template>
				</xsl:variable>
				<fo:inline baseline-shift="super" font-size="50%">
					<fo:basic-link>
						<xsl:attribute name="internal-destination">
							<xsl:value-of select="$id"/>
						</xsl:attribute>
						<xsl:value-of select="$count"/>
					</fo:basic-link>
				</fo:inline>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="put-footnote"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template name="put-footnote">
		<xsl:variable name="count">
			<xsl:call-template name="put-footnote-count">
				<xsl:with-param name="id" select="generate-id(.)"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="id">
			<xsl:call-template name="put-footnote-id">
				<xsl:with-param name="count" select="$count"/>
			</xsl:call-template>
		</xsl:variable>
		<fo:footnote>
			<fo:inline baseline-shift="super" font-size="50%">
				<fo:basic-link>
					<xsl:attribute name="internal-destination">
						<xsl:value-of select="$id"/>
					</xsl:attribute>
					<xsl:value-of select="$count"/>
				</fo:basic-link>
			</fo:inline>
			<fo:footnote-body>
				<fo:list-block id="{$id}">
					<fo:list-item>
						<xsl:call-template name="put-style-block-attr">
							<xsl:with-param name="style" select="$footnote-style"/>
						</xsl:call-template>
						<fo:list-item-label end-indent="label-end()">
							<fo:block>
								<xsl:value-of select="$count"/>
							</fo:block>
						</fo:list-item-label>
						<fo:list-item-body start-indent="body-start()">
							<fo:block>
								<xsl:apply-templates/>
							</fo:block>
						</fo:list-item-body>
					</fo:list-item>
				</fo:list-block>
			</fo:footnote-body>
		</fo:footnote>
	</xsl:template>

	<xsl:template match="bml:programco">
		<xsl:apply-templates select="bml:program" mode="co"/>
		<xsl:if test="bml:callouts">
			<fo:block>
				<xsl:call-template name="put-id-attr"/>
				<xsl:call-template name="put-style-block-attr">
					<xsl:with-param name="style" select="$callouts-style"/>
				</xsl:call-template>
				<xsl:for-each select="bml:callouts/bml:callout">
					<xsl:variable name="areaname" select="@area"/>
					<xsl:variable name="areacount">
						<xsl:for-each
							select="../../bml:areaspec/bml:area | ../../bml:areaspec/bml:areaset">
							<xsl:if test="@name = $areaname">
								<xsl:value-of select="position()"/>
							</xsl:if>
						</xsl:for-each>
					</xsl:variable>
					<fo:list-block>
						<fo:list-item>
							<fo:list-item-label end-indent="label-end()">
								<fo:block>
									<fo:external-graphic
										content-height="{$callout-style/@content-height}"
										src="{concat( 'url(', $directory/@callout-image, '/', $areacount, $callout-style/@image-ext, ')' )}"
									/>
								</fo:block>
							</fo:list-item-label>
							<fo:list-item-body start-indent="body-start()">
								<xsl:apply-templates/>
							</fo:list-item-body>
						</fo:list-item>
					</fo:list-block>
				</xsl:for-each>
			</fo:block>
		</xsl:if>
	</xsl:template>

	<xsl:template match="bml:code">
		<fo:inline>
			<xsl:call-template name="put-id-attr"/>
			<xsl:call-template name="put-style-block-attr">
				<xsl:with-param name="style" select="$code-style"/>
			</xsl:call-template>
			<xsl:value-of select="text()"/>
		</fo:inline>
	</xsl:template>

	<xsl:template match="bml:program">
		<fo:block white-space="pre">
			<xsl:call-template name="put-id-attr"/>
			<xsl:call-template name="put-style-block-attr">
				<xsl:with-param name="style" select="$program-style"/>
			</xsl:call-template>
			<xsl:call-template name="put-program-text"/>
		</fo:block>
	</xsl:template>

	<xsl:template name="put-program-text">
		<xsl:variable name="text" select="text()"/>
		<xsl:choose>
			<xsl:when test="contains($text, $cr)">
				<xsl:variable name="precr">
					<xsl:value-of select="substring-before($text, $cr)"/>
				</xsl:variable>
				<xsl:choose>
					<xsl:when test="string-length( normalize-space( $precr ) ) > 0">
						<xsl:value-of select="$text"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="substring-after($text, $cr)"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$text"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="bml:program" mode="co">
		<fo:block white-space="pre">
			<xsl:call-template name="put-id-attr"/>
			<xsl:call-template name="put-style-block-attr">
				<xsl:with-param name="style" select="$program-style"/>
			</xsl:call-template>
			<xsl:variable name="text" select="text()"/>
			<!--			<xsl:variable name="startcoord">
				<xsl:choose>
					<xsl:when test="contains( $text, $cr )">
						<xsl:variable name="precr">
							<xsl:value-of select="substring-before( text(), $cr)"/>
						</xsl:variable>
						<xsl:choose>
							<xsl:when test="string-length( normalize-space( $precr ) ) > 0">1</xsl:when>
							<xsl:otherwise>1</xsl:otherwise>
						</xsl:choose>		
					</xsl:when>
					<xsl:otherwise>0</xsl:otherwise>
				</xsl:choose>
			</xsl:variable>
-->
			<xsl:call-template name="put-program-line">
				<xsl:with-param name="coord" select="1"/>
				<xsl:with-param name="text">
					<xsl:call-template name="put-program-text"/>
				</xsl:with-param>
			</xsl:call-template>
		</fo:block>
	</xsl:template>

	<xsl:template name="put-program-line">
		<xsl:param name="coord"/>
		<xsl:param name="text"/>
		<xsl:choose>
			<xsl:when test="contains( $text, $cr )">
				<xsl:value-of select="substring-before( $text, $cr )"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$text"/>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:variable name="areaspec" select="../bml:areaspec"/>
		<xsl:variable name="matching" select="$areaspec//bml:area[ @coord = $coord ]"/>
		<xsl:if test="$matching">
			<xsl:text> </xsl:text>
			<xsl:for-each select="$areaspec//bml:area[ @coord = $coord ]">
				<xsl:variable name="area" select="generate-id()"/>
				<xsl:variable name="area-index">
					<xsl:choose>
						<xsl:when test="ancestor::bml:areaset">
							<xsl:variable name="areaset"
								select="generate-id( ancestor::bml:areaset )"/>
							<xsl:for-each
								select="$areaspec/*[ local-name() = 'area' or local-name() = 'areaset' ]">
								<xsl:if test="$areaset = generate-id()">
									<xsl:value-of select="position()"/>
								</xsl:if>
							</xsl:for-each>
						</xsl:when>
						<xsl:otherwise>
							<xsl:for-each
								select="$areaspec/*[ local-name() = 'area' or local-name() = 'areaset' ]">
								<xsl:if test="$area = generate-id()">
									<xsl:value-of select="position()"/>
								</xsl:if>
							</xsl:for-each>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<!-- to retain linefeed with indented xsl output -->
				<xsl:variable name="url"
					select="concat( 'url(', $directory/@callout-image, '/', $area-index, $callout-style/@image-ext, ')' )"/>
				<xsl:text disable-output-escaping="yes">&lt;</xsl:text>
				<xsl:text>fo:external-graphic content-height=&apos;</xsl:text>
				<xsl:value-of select="$callout-style/@content-height"/>
				<xsl:text>&apos; src=&apos;</xsl:text>
				<xsl:value-of select="$url"/>
				<xsl:text>&apos;</xsl:text>
				<xsl:text disable-output-escaping="yes">/&gt;</xsl:text>
			</xsl:for-each>
		</xsl:if>
		<xsl:value-of select="$cr"/>
		<xsl:if test="contains( $text, $cr )">
			<xsl:call-template name="put-program-line">
				<xsl:with-param name="coord" select="$coord + 1"/>
				<xsl:with-param name="text" select="substring-after($text, $cr)"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<xsl:template match="bml:areaspec"/>
	<xsl:template match="bml:callouts"/>

	<xsl:template match="bml:important">
		<xsl:call-template name="put-admonition">
			<xsl:with-param name="style" select="$important-style"/>
		</xsl:call-template>
	</xsl:template>

	<xsl:template match="bml:warning">
		<xsl:call-template name="put-admonition">
			<xsl:with-param name="style" select="$warning-style"/>
		</xsl:call-template>
	</xsl:template>

	<xsl:template match="bml:note">
		<xsl:call-template name="put-admonition">
			<xsl:with-param name="style" select="$note-style"/>
		</xsl:call-template>
	</xsl:template>

	<xsl:template name="put-admonition">
		<xsl:param name="style"/>
		<fo:list-block>
			<xsl:call-template name="put-id-attr"/>
			<xsl:call-template name="put-style-block-attr">
				<xsl:with-param name="style" select="$admonition-style"/>
			</xsl:call-template>
			<fo:list-item>
				<fo:list-item-label end-indent="label-end()">
					<fo:block>
						<xsl:variable name="path"
							select="concat( 'url(', $directory/@default-image, '/', $style/@image, ')' )"/>
						<fo:external-graphic src="{$path}">
							<xsl:if test="$style/@content-width">
								<xsl:attribute name="content-width">
									<xsl:value-of select="$style/@content-width"/>
								</xsl:attribute>
							</xsl:if>
							<xsl:if test="$style/@content-height">
								<xsl:attribute name="content-height">
									<xsl:value-of select="$style/@content-height"/>
								</xsl:attribute>
							</xsl:if>
						</fo:external-graphic>
					</fo:block>
				</fo:list-item-label>
				<fo:list-item-body>
					<xsl:attribute name="start-indent">
						<xsl:value-of select="$style/@text-indent"/>
					</xsl:attribute>
					<xsl:if test="bml:title">
						<fo:block>
							<xsl:call-template name="put-style-block-attr">
								<xsl:with-param name="style" select="$admonition-title-style"/>
							</xsl:call-template>
							<xsl:value-of select="bml:title"/>
						</fo:block>
					</xsl:if>
					<fo:block>
						<xsl:call-template name="put-style-block-attr">
							<xsl:with-param name="style" select="$admonition-body-style"/>
						</xsl:call-template>
						<xsl:apply-templates/>
					</fo:block>
				</fo:list-item-body>
			</fo:list-item>
		</fo:list-block>
		<xsl:call-template name="put-post-footnote"/>
	</xsl:template>

	<xsl:template match="bml:title"/>

	<xsl:template name="put-chapter-id">
		<xsl:variable name="ename">
			<xsl:for-each
				select="ancestor-or-self::bml:chapter | ancestor-or-self::bml:appendix | ancestor-or-self::bml:glossary | ancestor-or-self::bml:index | ancestor-or-self::bml:preface | ancestor-or-self::bml:foreword">
				<xsl:value-of select="local-name()"/>
			</xsl:for-each>
		</xsl:variable>
		<xsl:choose>
			<xsl:when test="$ename = 'appendix'">
				<xsl:variable name="count">
					<xsl:number count="/*/bml:appendix" format="A"/>
				</xsl:variable>
				<xsl:value-of select="concat( 'appendix', '-', $count )"/>
			</xsl:when>
			<xsl:when test="$ename = 'chapter'">
				<xsl:variable name="count">
					<xsl:number count="/*/bml:chapter"/>
				</xsl:variable>
				<xsl:value-of select="concat( 'chapter', '-', $count )"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$ename"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template name="put-footnote-id">
		<xsl:param name="count"/>
		<xsl:variable name="chapid">
			<xsl:call-template name="put-chapter-id"/>
		</xsl:variable>
		<xsl:value-of select="concat( 'footnote', '-', $chapid, '-', $count )"/>
	</xsl:template>

	<xsl:template match="bml:sect1">
		<xsl:if test="/bml:article">
			<fo:block>
				<xsl:call-template name="put-style-block-attr">
					<xsl:with-param name="style" select="$article-sect1-before-style"/>
				</xsl:call-template>
			</fo:block>
		</xsl:if>
		<xsl:variable name="chapid">
			<xsl:call-template name="put-chapter-id"/>
		</xsl:variable>
		<xsl:variable name="count">
			<xsl:number count="bml:sect1"/>
		</xsl:variable>
		<xsl:variable name="sect1id">
			<xsl:value-of select="concat( $chapid, '-sect1-', $count )"/>
		</xsl:variable>
		<xsl:call-template name="put-id-attr-block"/>
		<fo:block id="{$sect1id}">
			<xsl:call-template name="put-style-block-attr">
				<xsl:with-param name="style" select="$section-title-style"/>
			</xsl:call-template>
			<fo:marker marker-class-name="sect1-title">
				<xsl:value-of select="bml:title"/>
			</fo:marker>
			<xsl:value-of select="bml:title"/>
		</fo:block>
		<xsl:apply-templates>
			<xsl:with-param name="sect1id" select="$sect1id"/>
		</xsl:apply-templates>
	</xsl:template>

	<xsl:template match="bml:sect2">
		<xsl:param name="sect1id"/>
		<xsl:variable name="count">
			<xsl:number count="bml:sect2"/>
		</xsl:variable>
		<xsl:variable name="sect2id">
			<xsl:value-of select="concat( $sect1id, '-sect2-', $count )"/>
		</xsl:variable>
		<xsl:call-template name="put-id-attr-block"/>
		<fo:block id="{$sect2id}">
			<xsl:call-template name="put-style-block-attr">
				<xsl:with-param name="style" select="$section-title-style"/>
			</xsl:call-template>
			<fo:block font-size="77%">
				<xsl:value-of select="bml:title"/>
			</fo:block>
		</fo:block>
		<xsl:apply-templates>
			<xsl:with-param name="sect2id" select="$sect2id"/>
		</xsl:apply-templates>
	</xsl:template>

	<xsl:template match="bml:sect3">
		<xsl:param name="sect2id"/>
		<xsl:variable name="count">
			<xsl:number count="bml:sect3"/>
		</xsl:variable>
		<xsl:variable name="sect3id">
			<xsl:value-of select="concat( $sect2id, '-sect3-', $count )"/>
		</xsl:variable>
		<xsl:call-template name="put-id-attr-block"/>
		<fo:block id="{$sect3id}">
			<xsl:call-template name="put-style-block-attr">
				<xsl:with-param name="style" select="$section-title-style"/>
			</xsl:call-template>
			<fo:block font-size="65%">
				<xsl:value-of select="bml:title"/>
			</fo:block>
		</fo:block>
		<xsl:apply-templates/>
	</xsl:template>

	<xsl:template name="put-style-block-attr">
		<xsl:param name="style"/>
		<xsl:for-each select="$style/@*">
			<xsl:variable name="name" select="name()"/>
			<xsl:choose>
				<xsl:when test="$name = 'name'"/>
				<xsl:when test="$name = 'open-char' or $name = 'close-char'"/>
				<xsl:when test="$name = 'font-family'">
					<xsl:call-template name="put-font-family-attr">
						<xsl:with-param name="style" select="$style"/>
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
					<xsl:if test="not( starts-with( $name, '_' ) )">
						<xsl:attribute name="{$name}">
							<xsl:value-of select="."/>
						</xsl:attribute>
					</xsl:if>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
	</xsl:template>

	<xsl:template name="put-font-family-attr">
		<xsl:param name="style"/>
		<xsl:if test="$style/@font-family">
			<xsl:attribute name="font-family">
				<xsl:value-of select="( $cfg//font-family[ @name = $style/@font-family ] )[last()]"
				/>
			</xsl:attribute>
		</xsl:if>
	</xsl:template>

	<xsl:template name="put-author-name">
		<xsl:param name="editing" select="true()"/>
		<xsl:choose>
			<xsl:when test="bml:name">
				<xsl:value-of select="bml:name"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:choose>
					<xsl:when test="$author-surname-first = 'true'">
						<xsl:value-of select="bml:surname"/>
						<xsl:text> </xsl:text>
						<xsl:value-of select="bml:firstname"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="bml:firstname"/>
						<xsl:text> </xsl:text>
						<xsl:value-of select="bml:surname"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:variable name="authorid">
			<xsl:value-of select="@id"/>
		</xsl:variable>
		<xsl:if test="//bml:editing[ @author = $authorid ] and $editing = 'true'">
			<fo:inline keep-together.within-line="always" font-size="80%">
				<xsl:text> editing</xsl:text>
				<xsl:for-each select="//bml:editing[ @author = $authorid ]">
					<xsl:variable name="id" select="generate-id(.)"/>
					<xsl:if test="position() > 1">
						<xsl:text>,</xsl:text>
					</xsl:if>
					<fo:basic-link internal-destination="{$id}">
						<xsl:text> </xsl:text>
						<fo:page-number-citation ref-id="{$id}"/>
						<xsl:text>p</xsl:text>
					</fo:basic-link>
				</xsl:for-each>
			</fo:inline>
		</xsl:if>
	</xsl:template>

	<xsl:template match="bml:info">
		<xsl:choose>
			<xsl:when test="/bml:book">
				<fo:marker marker-class-name="book-title">
					<xsl:value-of select="bml:title"/>
				</fo:marker>
				<xsl:call-template name="put-info">
					<xsl:with-param name="doc-title-style" select="$book-title-style"/>
					<xsl:with-param name="doc-subtitle-style" select="$book-subtitle-style"/>
					<xsl:with-param name="doc-title-after-style" select="$book-title-after-style"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<fo:marker marker-class-name="article-title">
					<xsl:value-of select="bml:title"/>
				</fo:marker>
				<xsl:call-template name="put-info">
					<xsl:with-param name="doc-title-style" select="$article-title-style"/>
					<xsl:with-param name="doc-subtitle-style" select="$article-subtitle-style"/>
					<xsl:with-param name="doc-title-after-style" select="$article-title-after-style"
					/>
				</xsl:call-template>
				<fo:block>
					<xsl:call-template name="put-style-block-attr">
						<xsl:with-param name="style" select="$article-info-style"/>
					</xsl:call-template>
					<xsl:if test="bml:pubdate">
						<xsl:for-each select="bml:pubdate">
							<xsl:value-of select="$pubdate-text"/>
							<xsl:text> </xsl:text>
							<xsl:value-of select="."/>
						</xsl:for-each>
						<fo:block>
							<xsl:call-template name="put-style-block-attr">
								<xsl:with-param name="style" select="$article-sect1-before-style"/>
							</xsl:call-template>
						</fo:block>
					</xsl:if>
				</fo:block>
				<xsl:apply-templates select="bml:revhistory"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template name="put-info">
		<xsl:param name="doc-title-style"/>
		<xsl:param name="doc-subtitle-style"/>
		<xsl:param name="doc-title-after-style"/>
		<fo:block>
			<xsl:call-template name="put-style-block-attr">
				<xsl:with-param name="style" select="$doc-title-style"/>
			</xsl:call-template>
			<xsl:if test="$doc-title-style/@font-weight">
				<xsl:attribute name="font-weight">
					<xsl:value-of select="$doc-title-style/@font-weight"/>
				</xsl:attribute>
			</xsl:if>
			<xsl:value-of select="bml:title"/>
		</fo:block>
		<xsl:if test="bml:subtitle">
			<fo:block>
				<xsl:call-template name="put-style-block-attr">
					<xsl:with-param name="style" select="$doc-subtitle-style"/>
				</xsl:call-template>
				<xsl:if test="$doc-subtitle-style/@font-weight">
					<xsl:attribute name="font-weight">
						<xsl:value-of select="$doc-subtitle-style/@font-weight"/>
					</xsl:attribute>
				</xsl:if>
				<xsl:value-of select="bml:subtitle"/>
			</fo:block>
		</xsl:if>
		<fo:block>
			<xsl:call-template name="put-style-block-attr">
				<xsl:with-param name="style" select="$doc-title-after-style"/>
			</xsl:call-template>
		</fo:block>
		<xsl:for-each select="bml:author">
			<fo:block>
				<xsl:call-template name="put-id-attr"/>
				<xsl:if test="$author-style/@font-family">
					<xsl:call-template name="put-font-family-attr">
						<xsl:with-param name="style" select="$author-style"/>
					</xsl:call-template>
				</xsl:if>
				<xsl:if test="$author-style/@font-size">
					<xsl:attribute name="font-size">
						<xsl:value-of select="$author-style/@font-size"/>
					</xsl:attribute>
				</xsl:if>
				<xsl:if test="$author-style/@text-align">
					<xsl:attribute name="text-align">
						<xsl:value-of select="$author-style/@text-align"/>
					</xsl:attribute>
				</xsl:if>
				<xsl:if test="$author-style/@margin-top">
					<xsl:attribute name="margin-top">
						<xsl:value-of select="$author-style/@margin-top"/>
					</xsl:attribute>
				</xsl:if>
				<xsl:if test="$author-style/@margin-bottom and not( bml:orgname or bml:email )">
					<xsl:attribute name="margin-bottom">
						<xsl:value-of select="$author-style/@margin-bottom"/>
					</xsl:attribute>
				</xsl:if>
				<xsl:if test="$author-style/@margin-left">
					<xsl:attribute name="margin-left">
						<xsl:value-of select="$author-style/@margin-left"/>
					</xsl:attribute>
				</xsl:if>
				<xsl:if test="$author-style/@margin-right">
					<xsl:attribute name="margin-right">
						<xsl:value-of select="$author-style/@margin-right"/>
					</xsl:attribute>
				</xsl:if>
				<xsl:call-template name="put-author-name"/>
			</fo:block>
			<xsl:if test="bml:orgname or bml:email">
				<fo:block>
					<xsl:if test="$author-style/@font-size">
						<xsl:attribute name="font-size">
							<xsl:value-of select="$author-style/@font-size * 0.8"/>
						</xsl:attribute>
					</xsl:if>
					<xsl:if test="$author-style/@text-align">
						<xsl:attribute name="text-align">
							<xsl:value-of select="$author-style/@text-align"/>
						</xsl:attribute>
					</xsl:if>
					<xsl:if test="$author-style/@margin-bottom">
						<xsl:attribute name="margin-bottom">
							<xsl:value-of select="$author-style/@margin-bottom"/>
						</xsl:attribute>
					</xsl:if>
					<xsl:if test="$author-style/@margin-left">
						<xsl:attribute name="margin-left">
							<xsl:value-of select="$author-style/@margin-left"/>
						</xsl:attribute>
					</xsl:if>
					<xsl:if test="$author-style/@margin-right">
						<xsl:attribute name="margin-right">
							<xsl:value-of select="$author-style/@margin-right"/>
						</xsl:attribute>
					</xsl:if>
					<xsl:text> ( </xsl:text>
					<xsl:if test="bml:orgname">
						<xsl:value-of select="bml:orgname"/>
						<xsl:text>, </xsl:text>
					</xsl:if>
					<xsl:value-of select="bml:email"/>
					<xsl:text> )</xsl:text>
				</fo:block>
			</xsl:if>
		</xsl:for-each>
		<xsl:if test="bml:author">
			<fo:block>
				<xsl:choose>
					<xsl:when test="/bml:book">
						<xsl:call-template name="put-style-block-attr">
							<xsl:with-param name="style" select="$book-author-after-style"/>
						</xsl:call-template>
					</xsl:when>
					<xsl:otherwise>
						<xsl:call-template name="put-style-block-attr">
							<xsl:with-param name="style" select="$article-sect1-before-style"/>
						</xsl:call-template>
					</xsl:otherwise>
				</xsl:choose>
			</fo:block>
		</xsl:if>
	</xsl:template>

	<xsl:template match="bml:ednotice">
		<fo:block break-before="page">
			<xsl:apply-templates/>
		</fo:block>
	</xsl:template>

	<xsl:template match="bml:revhistory">
		<fo:block>
			<xsl:choose>
				<xsl:when test="/bml:book">
					<xsl:attribute name="break-before">page</xsl:attribute>
					<xsl:call-template name="put-style-block-attr">
						<xsl:with-param name="style" select="$revhistory-style"/>
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="put-style-block-attr">
						<xsl:with-param name="style" select="$section-title-style"/>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:value-of select="$revhistory-text"/>
		</fo:block>
		<fo:block>
			<xsl:if test="bml:revision">
				<fo:table>
					<fo:table-column column-number="1">
						<xsl:attribute name="column-width">
							<xsl:value-of select="$revision-style/@column1-width"/>
						</xsl:attribute>
					</fo:table-column>
					<fo:table-column column-number="2">
						<xsl:attribute name="column-width">
							<xsl:value-of select="$revision-style/@column2-width"/>
						</xsl:attribute>
					</fo:table-column>
					<fo:table-column column-number="3">
						<xsl:attribute name="column-width">
							<xsl:value-of select="$revision-style/@column3-width"/>
						</xsl:attribute>
					</fo:table-column>
					<fo:table-body>
						<xsl:for-each select="bml:revision">
							<xsl:sort select="@date" order="descending"/>
							<xsl:if test="@version">
								<fo:table-row>
									<fo:table-cell column-number="2" display-align="center">
										<xsl:call-template name="put-revision-cell-attr"/>
										<fo:block text-align="center">
											<xsl:call-template name="put-style-block-attr">
												<xsl:with-param name="style"
												select="$revision-number-style"/>
											</xsl:call-template>
											<!--											<fo:leader leader-pattern="dots" alignment-baseline="central"/>
-->
											<xsl:value-of select="$revision-text"/>
											<xsl:text> </xsl:text>
											<xsl:value-of select="@version"/>
											<!--<xsl:text> </xsl:text>
											<fo:leader leader-pattern="dots" alignment-baseline="central"/>-->
										</fo:block>
									</fo:table-cell>
								</fo:table-row>
							</xsl:if>
							<fo:table-row>
								<fo:table-cell display-align="center">
									<xsl:call-template name="put-revision-cell-attr"/>
									<fo:block>
										<xsl:value-of select="@date"/>
									</fo:block>
								</fo:table-cell>
								<fo:table-cell display-align="center">
									<xsl:call-template name="put-revision-cell-attr"/>
									<xsl:apply-templates select="bml:revdesc | bml:revremark"/>
									<xsl:if test="not(generate-id(.) = $last-revision-id)">
										<fo:block text-align-last="justify">
											<fo:leader leader-pattern="dots"
												leader-pattern-width="0.3cm"/>
										</fo:block>
									</xsl:if>
								</fo:table-cell>
								<fo:table-cell display-align="center">
									<xsl:call-template name="put-revision-cell-attr"/>
									<xsl:for-each select="bml:revauthor">
										<fo:block text-align="right">
											<xsl:variable name="id" select="@id"/>
											<xsl:for-each
												select="//bml:info/bml:author[ @id = $id ]">
												<xsl:call-template name="put-author-name">
												<xsl:with-param name="editing" select="false()"
												/>
												</xsl:call-template>
											</xsl:for-each>
										</fo:block>
									</xsl:for-each>
								</fo:table-cell>
							</fo:table-row>
						</xsl:for-each>
					</fo:table-body>
				</fo:table>
			</xsl:if>
		</fo:block>
		<fo:block>
			<xsl:call-template name="put-style-block-attr">
				<xsl:with-param name="style" select="$article-sect1-before-style"/>
			</xsl:call-template>
		</fo:block>
	</xsl:template>

	<xsl:template name="put-revision-cell-attr">
		<xsl:if test="$revision-style/@*[ contains( name(), 'padding' ) ]">
			<xsl:for-each select="$revision-style/@*[ contains( name(), 'padding' ) ]">
				<xsl:variable name="name" select="name()"/>
				<xsl:attribute name="{$name}">
					<xsl:value-of select="."/>
				</xsl:attribute>
			</xsl:for-each>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="bml:revremark">
		<fo:block>
			<xsl:apply-templates/>
		</fo:block>
	</xsl:template>

	<xsl:template match="bml:revdesc">
		<fo:block>
			<xsl:apply-templates/>
		</fo:block>
	</xsl:template>

	<xsl:template match="bml:dedication">
		<fo:block break-before="page">
			<xsl:call-template name="put-style-block-attr">
				<xsl:with-param name="style" select="$dedication-style"/>
			</xsl:call-template>
			<xsl:apply-templates mode="raw"/>
		</fo:block>
	</xsl:template>

	<xsl:template match="bml:para">
		<fo:block>
			<xsl:call-template name="put-para-attrs"/>
			<xsl:apply-templates/>
		</fo:block>
	</xsl:template>

	<xsl:template match="bml:cell/text()">
		<xsl:value-of select="."/>
	</xsl:template>

	<xsl:template name="put-para-attrs">
		<xsl:call-template name="put-id-attr"/>
		<xsl:call-template name="put-style-block-attr">
			<xsl:with-param name="style" select="$para-style"/>
		</xsl:call-template>
	</xsl:template>

	<xsl:template match="bml:para" mode="raw">
		<fo:block>
			<xsl:value-of select="."/>
		</fo:block>
	</xsl:template>

	<xsl:template name="put-caption">
		<xsl:param name="capheader"/>
		<xsl:if test="$capheader or @caption">
			<fo:block>
				<xsl:call-template name="put-style-block-attr">
					<xsl:with-param name="style" select="$caption-style"/>
				</xsl:call-template>
				<xsl:attribute name="text-align">
					<xsl:choose>
						<xsl:when test="@capalign">
							<xsl:value-of select="@capalign"/>
						</xsl:when>
						<xsl:otherwise>left</xsl:otherwise>
					</xsl:choose>
				</xsl:attribute>
				<xsl:if test="$capheader">
					<xsl:value-of select="$capheader"/>
					<xsl:if test="@caption">
						<xsl:text>. </xsl:text>
					</xsl:if>
				</xsl:if>
				<xsl:value-of select="@caption"/>
			</fo:block>
		</xsl:if>
	</xsl:template>

	<xsl:template match="bml:olist">
		<xsl:variable name="format">
			<xsl:choose>
				<xsl:when test="@numeration = 'loweralpha'">a</xsl:when>
				<xsl:when test="@numeration = 'lowerroman'">i</xsl:when>
				<xsl:when test="@numeration = 'upperalpha'">A</xsl:when>
				<xsl:when test="@numeration = 'upperroman'">I</xsl:when>
				<xsl:otherwise>1</xsl:otherwise>
			</xsl:choose>	
		</xsl:variable>
		<xsl:call-template name="put-id-attr-block"/>
		<xsl:call-template name="put-caption"/>
		<fo:list-block>
			<xsl:call-template name="put-style-block-attr">
				<xsl:with-param name="style" select="$list-style"/>
			</xsl:call-template>
			<xsl:apply-templates>
				<xsl:with-param name="format" select="$format"/>
			</xsl:apply-templates>
		</fo:list-block>
		<xsl:call-template name="put-post-footnote"/>
	</xsl:template>

	<xsl:template match="bml:ulist">
		<xsl:call-template name="put-id-attr-block"/>
		<xsl:call-template name="put-caption"/>
		<fo:list-block>
			<xsl:call-template name="put-style-block-attr">
				<xsl:with-param name="style" select="$list-style"/>
			</xsl:call-template>
			<xsl:apply-templates/>
		</fo:list-block>
		<xsl:call-template name="put-post-footnote"/>
	</xsl:template>

	<xsl:template name="put-post-footnote">
		<xsl:if
			test="not( ancestor::bml:ulist or ancestor::bml:olist or ancestor::bml:table or ancestor::bml:important or ancestor::bml:note or ancestor::bml:warning )">
			<xsl:for-each select="descendant::bml:footnote">
				<xsl:variable name="count">
					<xsl:call-template name="put-footnote-count">
						<xsl:with-param name="id" select="generate-id(.)"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:variable name="id">
					<xsl:call-template name="put-footnote-id">
						<xsl:with-param name="count" select="$count"/>
					</xsl:call-template>
				</xsl:variable>
				<fo:block>
					<fo:footnote>
						<fo:inline font-size="8pt" vertical-align="super"/>
						<fo:footnote-body>
							<fo:list-block id="{$id}">
								<fo:list-item>
									<xsl:call-template name="put-style-block-attr">
										<xsl:with-param name="style" select="$footnote-style"/>
									</xsl:call-template>
									<fo:list-item-label end-indent="label-end()">
										<fo:block>
											<xsl:value-of select="$count"/>
										</fo:block>
									</fo:list-item-label>
									<fo:list-item-body start-indent="body-start()">
										<fo:block>
											<xsl:apply-templates/>
										</fo:block>
									</fo:list-item-body>
								</fo:list-item>
							</fo:list-block>
						</fo:footnote-body>
					</fo:footnote>
				</fo:block>
			</xsl:for-each>
		</xsl:if>
	</xsl:template>

	<xsl:template match="bml:olist/bml:li">
		<xsl:param name="format"/>
		<fo:list-item>
			<fo:list-item-label end-indent="label-end()" text-align="start">
				<fo:block>
					<xsl:number count="bml:li" format="{$format}"/>.
				</fo:block>
			</fo:list-item-label>
			<fo:list-item-body start-indent="body-start()" text-align="start">
				<xsl:apply-templates/>
			</fo:list-item-body>
		</fo:list-item>
	</xsl:template>

	<xsl:template match="bml:ulist/bml:li">
		<xsl:param name="format"/>
		<fo:list-item>
			<fo:list-item-label end-indent="label-end()" text-align="start">
				<fo:block>
					<xsl:text>&#x2022;</xsl:text>
				</fo:block>
			</fo:list-item-label>
			<fo:list-item-body start-indent="body-start()" text-align="start">
				<xsl:apply-templates/>
			</fo:list-item-body>
		</fo:list-item>
	</xsl:template>

	<xsl:template name="put-table-max-col">
		<xsl:for-each select="bml:thead | bml:tfoot | bml:tbody/bml:row ">
			<xsl:sort select="count( bml:cell )" order="descending"/>
			<xsl:if test="position() = 1">
				<xsl:value-of select="count( bml:cell )"/>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>

	<xsl:template name="put-table-columns">
		<xsl:param name="count"/>
		<xsl:param name="max"/>
		<xsl:if test="$count &lt;= $max">
			<fo:table-column>
				<xsl:attribute name="column-number">
					<xsl:value-of select="$count"/>
				</xsl:attribute>
				<xsl:if test="bml:colspec[ position() = $count ]/@width">
					<xsl:attribute name="column-width">
						<xsl:value-of select="bml:colspec[ position() = $count ]/@width"/>
					</xsl:attribute>
				</xsl:if>
			</fo:table-column>
			<xsl:call-template name="put-table-columns">
				<xsl:with-param name="max" select="$max"/>
				<xsl:with-param name="count" select="$count + 1"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<xsl:template match="bml:table">
		<xsl:variable name="numcol">
			<xsl:value-of select="@cols"/>
		</xsl:variable>
		<xsl:call-template name="put-id-attr-block"/>
		<xsl:call-template name="put-aligned-caption-and-content">
			<xsl:with-param name="nodes">
				<fo:table>
					<xsl:call-template name="put-table-attrs"/>
					<xsl:call-template name="put-table-columns">
						<xsl:with-param name="count" select="1"/>
						<xsl:with-param name="max" select="$numcol"/>
					</xsl:call-template>
					<xsl:apply-templates/>
				</fo:table>
			</xsl:with-param>
			<xsl:with-param name="capheader">
				<xsl:value-of select="$table-text"/>
				<xsl:text> </xsl:text>
				<xsl:choose>
					<xsl:when test="/bml:book">
						<xsl:call-template name="put-chapter-kind-index"/>
						<xsl:text>-</xsl:text>
						<xsl:number count="bml:table" level="any" from="bml:chapter" format="1"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:number count="//bml:table" level="any"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:with-param>
		</xsl:call-template>
		<xsl:call-template name="put-post-footnote"/>
	</xsl:template>

	<xsl:template name="put-chapter-kind-index">
		<xsl:choose>
			<xsl:when test="ancestor::bml:chapter">
				<xsl:number count="bml:chapter" from="bml:book"/>
			</xsl:when>
			<xsl:when test="ancestor::bml:appendix">
				<xsl:number count="bml:appendix" from="bml:book" format="A"/>
			</xsl:when>
		</xsl:choose>
	</xsl:template>

	<xsl:template name="put-table-column-loc">
		<xsl:attribute name="column-number">
			<xsl:choose>
				<xsl:when test="@align = 'center' or @align = 'right'">2</xsl:when>
				<xsl:otherwise>1</xsl:otherwise>
			</xsl:choose>
		</xsl:attribute>
	</xsl:template>

	<xsl:template match="bml:thead">
		<xsl:variable name="cellmatrix">
			<xsl:call-template name="put-cell-matrix"/>
		</xsl:variable>
		<fo:table-header>
			<xsl:apply-templates>
				<xsl:with-param name="cellmatrix" select="exsl:node-set( $cellmatrix )"/>
			</xsl:apply-templates>
		</fo:table-header>
	</xsl:template>

	<xsl:template match="bml:tfoot">
		<xsl:variable name="cellmatrix">
			<xsl:call-template name="put-cell-matrix"/>
		</xsl:variable>
		<fo:table-footer>
			<xsl:apply-templates>
				<xsl:with-param name="cellmatrix" select="exsl:node-set( $cellmatrix )"/>
			</xsl:apply-templates>
		</fo:table-footer>
	</xsl:template>

	<xsl:template name="put-cell-matrix-colspan">
		<xsl:param name="count"/>
		<xsl:if test="$count > 0">
			<cell/>
			<xsl:call-template name="put-cell-matrix-colspan">
				<xsl:with-param name="count" select="$count - 1"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<xsl:template name="put-cell-matrix">
		<xsl:if test="bml:row[1]">
			<xsl:call-template name="put-cell-matrix-row">
				<xsl:with-param name="cols" select="../@cols"/>
				<xsl:with-param name="row" select="bml:row[1]"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<xsl:template name="put-cell-matrix-morecell">
		<xsl:param name="count"/>
		<xsl:if test="$count > 0">
			<cell/>
			<xsl:call-template name="put-cell-matrix-morecell">
				<xsl:with-param name="count" select="$count - 1"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<xsl:template name="put-cell-matrix-cell">
		<xsl:param name="count"/>
		<xsl:param name="index"/>
		<xsl:param name="cell"/>
		<xsl:param name="prevrow"/>
		<xsl:variable name="nextcell" select="$cell/following-sibling::bml:cell[1]"/>
		<xsl:if test="$count >= $index">
			<xsl:choose>
				<xsl:when test="$prevrow and $prevrow/cell[ $index ]/@rowspan > 1">
					<cell>
						<xsl:attribute name="rowspan">
							<xsl:value-of select="$prevrow/cell[ $index ]/@rowspan - 1"/>
						</xsl:attribute>
					</cell>
					<xsl:call-template name="put-cell-matrix-cell">
						<xsl:with-param name="count" select="$count"/>
						<xsl:with-param name="index" select="$index + 1"/>
						<xsl:with-param name="cell" select="$cell"/>
						<xsl:with-param name="prevrow" select="$prevrow"/>
					</xsl:call-template>
				</xsl:when>
				<xsl:when test="$cell/@colspan > 0">
					<xsl:call-template name="copy-cell-matrix-cell">
						<xsl:with-param name="cell" select="$cell"/>
					</xsl:call-template>
					<xsl:call-template name="put-cell-matrix-morecell">
						<xsl:with-param name="count" select="$cell/@colspan - 1"/>
					</xsl:call-template>
					<xsl:call-template name="put-cell-matrix-cell">
						<xsl:with-param name="count" select="$count"/>
						<xsl:with-param name="index" select="$index + 1 + $cell/@colspan - 1"/>
						<xsl:with-param name="cell" select="$nextcell"/>
						<xsl:with-param name="prevrow" select="$prevrow"/>
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="copy-cell-matrix-cell">
						<xsl:with-param name="cell" select="$cell"/>
					</xsl:call-template>
					<xsl:call-template name="put-cell-matrix-cell">
						<xsl:with-param name="count" select="$count"/>
						<xsl:with-param name="index" select="$index + 1"/>
						<xsl:with-param name="cell" select="$nextcell"/>
						<xsl:with-param name="prevrow" select="$prevrow"/>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:if>
	</xsl:template>

	<xsl:template name="copy-cell-matrix-cell">
		<xsl:param name="cell"/>
		<cell cid="{generate-id($cell)}">
			<xsl:for-each select="$cell/@*">
				<xsl:choose>
					<xsl:when test="name() = 'colspan'"/>
					<xsl:otherwise>
						<xsl:copy/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:for-each>
			<xsl:copy-of select="$cell/* | $cell/text()"/>
		</cell>
	</xsl:template>

	<xsl:template name="put-cell-matrix-row">
		<xsl:param name="row"/>
		<xsl:param name="cols"/>
		<xsl:param name="prevrow"/>
		<xsl:variable name="nextrow" select="$row/following-sibling::bml:row[1]"/>
		<xsl:variable name="thisrow">
			<xsl:call-template name="put-cell-matrix-cell">
				<xsl:with-param name="count" select="$cols"/>
				<xsl:with-param name="index" select="1"/>
				<xsl:with-param name="cell" select="$row/bml:cell[1]"/>
				<xsl:with-param name="prevrow" select="$prevrow"/>
			</xsl:call-template>
		</xsl:variable>
		<row>
			<xsl:copy-of select="$thisrow"/>
		</row>
		<xsl:if test="$nextrow">
			<xsl:call-template name="put-cell-matrix-row">
				<xsl:with-param name="prevrow" select="exsl:node-set( $thisrow )"/>
				<xsl:with-param name="cols" select="$cols"/>
				<xsl:with-param name="row" select="$nextrow"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<xsl:template match="bml:tbody">
		<xsl:variable name="cellmatrix">
			<xsl:call-template name="put-cell-matrix"/>
		</xsl:variable>
		<!--		<xsl:text>cellmatrix</xsl:text>
		<xsl:copy-of select="$cellmatrix"/>
-->
		<fo:table-body start-indent="0">
			<xsl:apply-templates>
				<xsl:with-param name="cellmatrix" select="exsl:node-set( $cellmatrix )"/>
			</xsl:apply-templates>
		</fo:table-body>
	</xsl:template>

	<xsl:template name="put-table-attrs">
		<xsl:variable name="border" select="@border"/>
		<!-- put style attrs -->
		<xsl:for-each select="$table-style/@*">
			<xsl:variable name="name" select="name()"/>
			<xsl:choose>
				<xsl:when test="$name = 'name'"/>
				<xsl:when test="$name = 'font-family'">
					<xsl:call-template name="put-font-family-attr">
						<xsl:with-param name="style" select="$table-style"/>
					</xsl:call-template>
				</xsl:when>
				<xsl:when test="contains( $name, 'border' )">
					<xsl:if test="not( $border = 'false' )">
						<xsl:copy/>
					</xsl:if>
				</xsl:when>
				<xsl:otherwise>
					<xsl:attribute name="{$name}">
						<xsl:value-of select="."/>
					</xsl:attribute>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
		<!-- put table attrs -->
		<xsl:for-each select="@*">
			<xsl:variable name="name" select="name()"/>
			<xsl:choose>
				<xsl:when test="$name = 'caption'"/>
				<xsl:when test="$name = 'xml:id'"/>
				<xsl:when test="$name = 'width'"/>
				<xsl:when test="$name = 'align'"/>
				<xsl:when test="$name = 'capalign'"/>
				<xsl:when test="$name = 'border'"/>
				<xsl:when test="$name = 'cols'"/>
				<xsl:otherwise>
					<xsl:copy/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
	</xsl:template>

	<xsl:template name="put-disaply-align">
		<xsl:param name="tvalign"/>
		<xsl:if test="$tvalign">
			<xsl:attribute name="display-align">
				<xsl:choose>
					<xsl:when test="$tvalign = 'top'">before</xsl:when>
					<xsl:when test="$tvalign = 'bottom'">after</xsl:when>
					<xsl:when test="$tvalign = 'center'">center</xsl:when>
				</xsl:choose>
			</xsl:attribute>
		</xsl:if>
	</xsl:template>

	<xsl:template name="put-table-row-or-cell-attrs">
		<xsl:for-each select="@*">
			<xsl:variable name="name" select="name()"/>
			<xsl:choose>
				<xsl:when test="$name = 'talign'">
					<xsl:attribute name="text-align">
						<xsl:value-of select="."/>
					</xsl:attribute>
				</xsl:when>
				<xsl:when test="$name = 'tvalign'">
					<xsl:call-template name="put-disaply-align">
						<xsl:with-param name="tvalign" select="."/>
					</xsl:call-template>
				</xsl:when>
				<xsl:when test="$name = 'colspan'">
					<xsl:attribute name="number-columns-spanned">
						<xsl:value-of select="."/>
					</xsl:attribute>
				</xsl:when>
				<xsl:when test="$name = 'rowspan'">
					<xsl:attribute name="number-rows-spanned">
						<xsl:value-of select="."/>
					</xsl:attribute>
				</xsl:when>
				<xsl:when test="$name = 'bgcolor'">
					<xsl:attribute name="background-color">
						<xsl:value-of select="."/>
					</xsl:attribute>
				</xsl:when>
				<xsl:when test="$name = 'width'"/>
				<xsl:otherwise>
					<xsl:copy/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
	</xsl:template>

	<xsl:template match="bml:row">
		<xsl:param name="cellmatrix"/>
		<fo:table-row>
			<xsl:variable name="tregion">
				<xsl:value-of select="local-name( parent::* )"/>
			</xsl:variable>
			<xsl:choose>
				<xsl:when test="$tregion = 'thead'">
					<xsl:call-template name="put-style-block-attr">
						<xsl:with-param name="style" select="$table-header-style"/>
					</xsl:call-template>
				</xsl:when>
				<xsl:when test="$tregion = 'tfoot'">
					<xsl:call-template name="put-style-block-attr">
						<xsl:with-param name="style" select="$table-footer-style"/>
					</xsl:call-template>
				</xsl:when>
			</xsl:choose>
			<xsl:call-template name="put-table-row-or-cell-attrs"/>
			<xsl:apply-templates>
				<xsl:with-param name="cellmatrix" select="$cellmatrix"/>
			</xsl:apply-templates>
		</fo:table-row>
	</xsl:template>

	<xsl:template name="put-table-cell-style-attrs">
		<xsl:variable name="border" select="ancestor::bml:table/@border"/>
		<!-- put style attrs -->
		<xsl:for-each select="$table-cell-style/@*">
			<xsl:variable name="name" select="name()"/>
			<xsl:choose>
				<xsl:when test="$name = 'name'"/>
				<xsl:when test="$name = 'font-family'">
					<xsl:call-template name="put-font-family-attr">
						<xsl:with-param name="style" select="$table-cell-style"/>
					</xsl:call-template>
				</xsl:when>
				<xsl:when test="contains( $name, 'border' )">
					<xsl:if test="not( $border = 'false' )">
						<xsl:copy/>
					</xsl:if>
				</xsl:when>
				<xsl:otherwise>
					<xsl:attribute name="{$name}">
						<xsl:value-of select="."/>
					</xsl:attribute>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
	</xsl:template>

	<!-- TODO : Optimize -->
	<xsl:template name="put-cell-col">
		<xsl:param name="cid"/>
		<xsl:param name="cellmatrix"/>
		<xsl:for-each select="$cellmatrix/row">
			<xsl:for-each select="cell">
				<xsl:if test="@cid = $cid">
					<xsl:number count="cell"/>
				</xsl:if>
			</xsl:for-each>
		</xsl:for-each>
	</xsl:template>

	<xsl:template match="bml:cell">
		<xsl:param name="cellmatrix"/>
		<xsl:variable name="col">
			<xsl:call-template name="put-cell-col">
				<xsl:with-param name="cellmatrix" select="$cellmatrix"/>
				<xsl:with-param name="cid" select="generate-id()"/>
			</xsl:call-template>
		</xsl:variable>
		<fo:table-cell>
			<xsl:call-template name="put-table-cell-style-attrs"/>
			<xsl:call-template name="put-table-row-or-cell-attrs"/>
			<xsl:if test="not( ../bml:row/@talign ) and not( @talign )">
				<xsl:if test="../../../bml:colspec[ position() = $col ]/@talign">
					<xsl:attribute name="text-align">
						<xsl:value-of select="../../../bml:colspec[ position() = $col ]/@talign"/>
					</xsl:attribute>
				</xsl:if>
			</xsl:if>
			<xsl:if test="not( ../bml:row/@tvalign ) and not( @tvalign )">
				<xsl:if test="../../../bml:colspec[ position() = $col ]/@tvalign">
					<xsl:call-template name="put-disaply-align">
						<xsl:with-param name="tvalign">
							<xsl:value-of
								select="../../../bml:colspec[ position() = $col ]/@tvalign"/>
						</xsl:with-param>
					</xsl:call-template>
				</xsl:if>
			</xsl:if>
			<xsl:if test="not( ../bml:row/@bgcolor ) and not( @bgcolor )">
				<xsl:if test="../../../bml:colspec[ position() = $col ]/@bgcolor">
					<xsl:attribute name="background-color">
						<xsl:value-of select="../../../bml:colspec[ position() = $col ]/@bgcolor"/>
					</xsl:attribute>
				</xsl:if>
			</xsl:if>
			<fo:block>
				<xsl:apply-templates/>
			</fo:block>
		</fo:table-cell>
	</xsl:template>

	<xsl:template match="bml:image">
		<xsl:call-template name="put-aligned-caption-and-content">
			<xsl:with-param name="nodes">
				<fo:block>
					<xsl:call-template name="put-id-attr"/>
					<xsl:if test="@align">
						<xsl:attribute name="text-align">
							<xsl:value-of select="@align"/>
						</xsl:attribute>
					</xsl:if>
					<fo:external-graphic content-width="scale-to-fit" width="100%">
						<xsl:attribute name="src">
							<xsl:choose>
								<xsl:when test="string-length( $curdir ) > 0">
									<xsl:value-of select="concat( 'url(', $curdir, '/', @src, ')' )"
									/>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="concat( 'url(', @src, ')' )"/>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:attribute>
					</fo:external-graphic>
				</fo:block>
			</xsl:with-param>
			<xsl:with-param name="capheader">
				<xsl:value-of select="$image-text"/>
				<xsl:text> </xsl:text>
				<xsl:choose>
					<xsl:when test="/bml:book">
						<xsl:call-template name="put-chapter-kind-index"/>
						<xsl:text>-</xsl:text>
						<xsl:number count="bml:image" level="any" from="bml:chapter" format="1"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:number count="//bml:image" level="any"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:with-param>
		</xsl:call-template>
	</xsl:template>

	<xsl:template name="put-aligned-caption-and-content">
		<xsl:param name="nodes"/>
		<xsl:param name="capheader"/>
		<fo:table width="100%">
			<xsl:if test="@align = 'center' or @align = 'right'">
				<fo:table-column column-width="proportional-column-width(1)"/>
			</xsl:if>
			<fo:table-column>
				<xsl:if test="@width">
					<xsl:attribute name="column-width">
						<xsl:value-of select="@width"/>
					</xsl:attribute>
				</xsl:if>
			</fo:table-column>
			<xsl:if test="@align = 'center'">
				<fo:table-column column-width="proportional-column-width(1)"/>
			</xsl:if>
			<fo:table-body start-indent="0">
				<fo:table-row>
					<fo:table-cell>
						<xsl:call-template name="put-table-column-loc"/>
						<xsl:copy-of select="$nodes"/>
					</fo:table-cell>
				</fo:table-row>
				<xsl:if test="@caption">
					<fo:table-row>
						<fo:table-cell>
							<xsl:call-template name="put-table-column-loc"/>
							<xsl:call-template name="put-caption">
								<xsl:with-param name="capheader">
									<xsl:value-of select="$capheader"/>
								</xsl:with-param>
							</xsl:call-template>
						</fo:table-cell>
					</fo:table-row>
				</xsl:if>
			</fo:table-body>
		</fo:table>
	</xsl:template>

	<xsl:template match="bml:link">
		<fo:inline>
			<fo:basic-link>
				<xsl:choose>
					<xsl:when test="@refid">
						<xsl:attribute name="internal-destination">
							<xsl:value-of select="@refid"/>
						</xsl:attribute>
					</xsl:when>
					<xsl:when test="@url">
						<xsl:attribute name="external-destination">
							<xsl:value-of select="concat( 'url(', @url, ')' )"/>
						</xsl:attribute>
					</xsl:when>
				</xsl:choose>
				<xsl:choose>
					<xsl:when test="@deco">
						<xsl:variable name="type">
							<xsl:choose>
								<xsl:when test="@deco = 'underline'">underline</xsl:when>
								<xsl:when test="@deco = 'strike'">line-through</xsl:when>
							</xsl:choose>
						</xsl:variable>
						<xsl:if test="string-length(normalize-space($type))">
							<xsl:attribute name="text-decoration">
								<xsl:value-of select="$type"/>
							</xsl:attribute>
						</xsl:if>
					</xsl:when>
					<xsl:otherwise>
						<xsl:call-template name="put-style-block-attr">
							<xsl:with-param name="style" select="$emphasis-style"/>
						</xsl:call-template>
					</xsl:otherwise>
				</xsl:choose>
				<xsl:value-of select="text()"/>
			</fo:basic-link>
		</fo:inline>
	</xsl:template>

	<xsl:template name="put-see-index">
		<xsl:param name="seetext"/>
		<xsl:text> </xsl:text>
		<xsl:value-of select="substring-before( $seeindex-text, '%t' )"/>
		<xsl:value-of select="$seetext"/>
		<xsl:value-of select="substring-after( $seeindex-text, '%t' )"/>
	</xsl:template>

	<xsl:template match="bml:indexterm" mode="index">
		<xsl:variable name="prm" select="bml:primary"/>
		<xsl:if test="not( preceding::bml:indexterm[ bml:primary = $prm ] )">
			<fo:block>
				<xsl:value-of select="$prm"/>
				<xsl:choose>
					<xsl:when test="bml:see and not( bml:secondary )">
						<xsl:call-template name="put-see-index">
							<xsl:with-param name="seetext" select="bml:see"/>
						</xsl:call-template>
					</xsl:when>
					<xsl:otherwise>
						<fo:inline keep-together.within-line="always">
							<xsl:for-each select="key( 'primary-index', $prm )">
								<xsl:variable name="id" select="generate-id(.)"/>
								<xsl:if test="not( bml:secondary )">
									<xsl:text>, </xsl:text>
									<fo:basic-link internal-destination="{$id}">
										<fo:page-number-citation ref-id="{$id}"/>
									</fo:basic-link>
									<xsl:if test="@startid">
										<xsl:call-template name="put-range-index"/>
									</xsl:if>
									<xsl:if
										test="bml:seealso and not( following-sibling::bml:secondary )">
										<xsl:call-template name="put-seealso-index"/>
									</xsl:if>
								</xsl:if>
							</xsl:for-each>
						</fo:inline>
						<xsl:apply-templates select="key( 'primary-index', $prm )/bml:secondary"
							mode="index">
							<xsl:with-param name="prm" select="$prm"/>
							<xsl:sort/>
						</xsl:apply-templates>
					</xsl:otherwise>
				</xsl:choose>
			</fo:block>
		</xsl:if>
	</xsl:template>

	<xsl:template match="bml:secondary" mode="index">
		<xsl:param name="prm"/>
		<xsl:variable name="snd" select="."/>
		<xsl:if
			test="not( preceding::bml:indexterm[ bml:primary = $prm and bml:secondary = $snd ] )">
			<fo:block margin-left="0.5cm">
				<xsl:value-of select="$snd"/>
				<xsl:choose>
					<xsl:when
						test="following-sibling::bml:see and not( following-sibling::bml:tertiary )">
						<xsl:call-template name="put-see-index">
							<xsl:with-param name="seetext" select="following-sibling::bml:see"/>
						</xsl:call-template>
					</xsl:when>
					<xsl:otherwise>
						<fo:inline keep-together.within-line="always">
							<xsl:for-each
								select="key( 'secondary-index', concat( $prm, ':', $snd ) )">
								<xsl:variable name="id" select="generate-id(.)"/>
								<xsl:if test="not( bml:tertiary )">
									<xsl:text>, </xsl:text>
									<fo:basic-link internal-destination="{$id}">
										<fo:page-number-citation ref-id="{$id}"/>
									</fo:basic-link>
									<xsl:if test="@startid">
										<xsl:call-template name="put-range-index"/>
									</xsl:if>
									<xsl:if
										test="bml:seealso and not( following-sibling::bml:tertiary )">
										<xsl:call-template name="put-seealso-index"/>
									</xsl:if>
								</xsl:if>
							</xsl:for-each>
							<xsl:apply-templates
								select="key( 'secondary-index', concat( $prm, ':', $snd ) )/bml:tertiary"
								mode="index">
								<xsl:with-param name="prm" select="$prm"/>
								<xsl:with-param name="snd" select="$snd"/>
								<xsl:sort/>
							</xsl:apply-templates>
						</fo:inline>
					</xsl:otherwise>
				</xsl:choose>
			</fo:block>
		</xsl:if>
	</xsl:template>

	<xsl:template match="bml:tertiary" mode="index">
		<xsl:param name="prm"/>
		<xsl:param name="snd"/>
		<xsl:variable name="ttr" select="."/>
		<xsl:if
			test="not( preceding::bml:indexterm[ bml:primary = $prm and bml:secondary = $snd and bml:tertiary = $ttr ] )">
			<xsl:choose>
				<xsl:when test="following-sibling::bml:see">
					<xsl:call-template name="put-see-index">
						<xsl:with-param name="seetext" select="following-sibling::bml:see"/>
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
					<fo:block>
						<xsl:value-of select="$ttr"/>
						<fo:inline keep-together.within-line="always">
							<xsl:for-each
								select="key( 'tertiary-index', concat( $prm, ':', $snd, ':', $ttr ) )">
								<xsl:variable name="id" select="generate-id(.)"/>
								<xsl:text>, </xsl:text>
								<fo:basic-link internal-destination="{$id}">
									<fo:page-number-citation ref-id="{$id}"/>
								</fo:basic-link>
								<xsl:if test="@startid">
									<xsl:call-template name="put-range-index"/>
								</xsl:if>
								<xsl:if test="bml:seealso">
									<xsl:call-template name="put-seealso-index"/>
								</xsl:if>
							</xsl:for-each>
						</fo:inline>
					</fo:block>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:if>
	</xsl:template>

	<xsl:template name="put-range-index">
		<xsl:variable name="startid" select="@startid"/>
		<xsl:text>-</xsl:text>
		<xsl:for-each select="//bml:indexterm[ @startref = $startid ]">
			<xsl:variable name="endid" select="generate-id()"/>
			<fo:basic-link internal-destination="{$endid}">
				<fo:page-number-citation ref-id="{$endid}"/>
			</fo:basic-link>
		</xsl:for-each>
	</xsl:template>

	<xsl:template name="put-seealso-index">
		<xsl:value-of select="substring-before( $seealsoindex-text, '%t' )"/>
		<xsl:value-of select="bml:seealso"/>
		<xsl:value-of select="substring-after( $seealsoindex-text, '%t' )"/>
	</xsl:template>

	<xsl:template match="bml:indexterm">
		<fo:block>
			<xsl:attribute name="id">
				<xsl:value-of select="generate-id(.)"/>
			</xsl:attribute>
		</fo:block>
	</xsl:template>

	<xsl:template match="bml:quote">
		<fo:inline>
			<xsl:call-template name="put-style-block-attr">
				<xsl:with-param name="style" select="$quote-style"/>
			</xsl:call-template>
			<xsl:value-of select="$quote-style/@open-char"/>
			<xsl:apply-templates/>
			<xsl:value-of select="$quote-style/@close-char"/>
		</fo:inline>
	</xsl:template>

	<xsl:template match="bml:blockquote">
		<fo:block>
			<xsl:call-template name="put-style-block-attr">
				<xsl:with-param name="style" select="$blockquote-style"/>
			</xsl:call-template>
			<xsl:apply-templates/>
			<xsl:if test="bml:attribution">
				<fo:block text-align="end">
					<xsl:text> - </xsl:text>
					<xsl:value-of select="bml:attribution"/>
				</fo:block>
			</xsl:if>
		</fo:block>
	</xsl:template>

	<xsl:template match="bml:gloentry">
		<fo:block>
			<xsl:call-template name="put-style-block-attr">
				<xsl:with-param name="style" select="$glossary-term-style"/>
			</xsl:call-template>
			<xsl:value-of select="bml:gloterm"/>
		</fo:block>
		<fo:block>
			<xsl:call-template name="put-style-block-attr">
				<xsl:with-param name="style" select="$glossary-def-style"/>
			</xsl:call-template>
			<xsl:apply-templates select="bml:glodef/*"/>
		</fo:block>
	</xsl:template>

	<xsl:template match="bml:editing">
		<fo:block>
			<xsl:attribute name="id">
				<xsl:value-of select="generate-id()"/>
			</xsl:attribute>
		</fo:block>
	</xsl:template>

	<xsl:template match="bml:colspec"/>
	<xsl:template match="bml:revision"/>
	<xsl:template match="bml:attribution"/>

	<xsl:template match="bml:*">
		<xsl:text>&#10;</xsl:text>
		<xsl:text>Unmatched element found : '</xsl:text>
		<xsl:value-of select="name(..)"/>
		<xsl:text>/</xsl:text>
		<xsl:value-of select="name()"/>
		<xsl:text>'</xsl:text>
	</xsl:template>

	<xsl:template match="text()">
		<xsl:copy/>
	</xsl:template>

</xsl:stylesheet>
